ramsey / uuid-doctrine Goto Github PK
View Code? Open in Web Editor NEW:snowflake::file_cabinet: Allow the use of a ramsey/uuid UUID as Doctrine field type.
License: MIT License
:snowflake::file_cabinet: Allow the use of a ramsey/uuid UUID as Doctrine field type.
License: MIT License
Hi,
I am really confused about a very elementary question, which I described on SO clearly.
I'd be very thankful to get a concise answer. I think the documentation should also be complemented in this respect, which I would offer to do.
Thanks in advance,
Olli
When doctrine make query with array of uuids as parameter, every uuid cast to string.
Result match nothing, because need cast to Bytes.
Is only to extend Uuid class and replace behavior of __toString() method?
Hi, we're just using Doctrine DBAL, not the ORM. But to get these Type-Classes we have lots of dependencies here for the Generator, we don't want.
It would be nice to implement Percona's suggestion in a new binary mapping, something like UuidOptimisedBinaryType
.
Thoughts?
Please add to src/UuidType.php the code to avoid this problem
/**
* @param AbstractPlatform $platform
*
* @return array
*/
public function getMappedDatabaseTypes(AbstractPlatform $platform)
{
return [self::NAME];
}
i think its more a doctrine orm issue but thought it might be good to also report it here.
having a type class like that:
Type.php
:
public function __construct(?string $name = null, UuidInterface $id = null)
{
$this->id = ($id ? $id : Uuid::uuid4());
$this->name = $name;
}
/**
* @var \Ramsey\Uuid\UuidInterface
*
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")
*/
protected $id;
/**
* @return UuidInterface
*/
public function getId(): ?UuidInterface
{
return $this->id;
}
/**
* @param UuidInterface $id
*
* @return self
*/
public function setId(UuidInterface $id): self
{
$this->id = $id;
return $this;
}
...
having it integrated into symfony with doctrine and persisted via a command like that:
protected function execute(InputInterface $input, OutputInterface $output)
{
$doctrine = $this->getContainer()->get('doctrine');
$em = $doctrine->getManager();
$type = new Type('my type3', null, Uuid::fromString('59ba2202-449a-462a-a8bd-013b38dd57be'));
dump($type);
$em->persist($type);
dump($type);
...
in the first dump the uuid is correct 59ba2202-449a-462a-a8bd-013b38dd57be
but in the 2nd the autogenerator generates a new uuid.
I have a quite simple project where I'm trying to use UUID bundle. There are two connections (PostgreSQL as default and SQLite as secondary) and corresponding EntityManagers.
Right after installing in this (bd23236) code state I started to getting errors like this:
$ composer require ramsey/uuid-doctrine --ignore-platform-reqs
Using version ^1.4 for ramsey/uuid-doctrine
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Prefetching 2 packages 🎶 💨
- Downloading (100%)
Package operations: 3 installs, 0 updates, 0 removals
- Installing paragonie/random_compat (v2.0.15):
- Installing ramsey/uuid (3.7.3):
- Installing ramsey/uuid-doctrine (1.4.3):
Writing lock file
Generating autoload files
ocramius/package-versions: Generating version class...
ocramius/package-versions: ...done generating version class
Symfony operations: 1 recipe (08ddea6376c012d806872174273e8704)
- WARNING ramsey/uuid-doctrine (>=1.3): From github.com/symfony/recipes-contrib:master
The recipe for this package comes from the "contrib" repository, which is open to community contributions.
Review the recipe at https://github.com/symfony/recipes-contrib/tree/master/ramsey/uuid-doctrine/1.3
Do you want to execute this recipe?
[y] Yes
[n] No
[a] Yes for all packages, only for the current installation session
[p] Yes permanently, never ask again for this project
(defaults to n): y
- Configuring ramsey/uuid-doctrine (>=1.3): From github.com/symfony/recipes-contrib:master
Executing script cache:clear [KO]
[KO]
Script cache:clear returned with error code 1
!!
!! In ConnectionFactory.php line 87:
!!
!! An exception occured while establishing a connection to figure out your pla
!! tform version.
!! You can circumvent this by setting a 'server_version' configuration value
!!
!! For further information have a look at:
!! https://github.com/doctrine/DoctrineBundle/issues/673
!!
!!
!! In AbstractPostgreSQLDriver.php line 93:
!!
!! An exception occurred in driver: SQLSTATE[08006] [7] FATAL: role "root" do
!! es not exist
!!
!!
!! In PDOConnection.php line 50:
!!
!! SQLSTATE[08006] [7] FATAL: role "root" does not exist
!!
!!
!! In PDOConnection.php line 46:
!!
!! SQLSTATE[08006] [7] FATAL: role "root" does not exist
!!
!!
!!
Script @auto-scripts was called via post-update-cmd
If I just comment everything in just installed config/packages/ramsey_uuid_doctrine.yaml
then error disappearing.
P.S. I'm using --ignore-platform-reqs
only to avoid getting errors about PHP 7.2 in my require
section of composer.json
while currently using PHP 7.1 on different PC.
Hello,
I've encountered some unexpected behaviour using UUID's and doctrine relations:
Lets say I have the 2 following classes
Car
class Car
{
/**
* @var Uuid
*
* @ORM\Id()
* @ORM\Column(type="uuid")
*/
private $id;
/**
* @var Person
*
* @ORM\ManyToOne(targetEntity="Person")
*/
private $owner;
/**
* @return Uuid
*/
public function getId(): Uuid
{
return $this->id;
}
/**
* @return Person
*/
public function getOwner(): Person
{
return $this->owner;
}
}
Person
class Person
{
/**
* @var Uuid
*
* @ORM\Id()
* @ORM\Column(type="uuid")
*/
private $id;
/**
* @var string
*
* @ORM\Column(type="string")
*/
private $name;
/**
* @return Uuid
*/
public function getId(): Uuid
{
return $this->id;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
}
Using it as follows errors with: Expected return type of UUID, string returned
$car = $this->carRepo->findOneById($id);
$car->getOwner()->getId(); /** returns string */
The following does work
$car = $this->carRepo->findOneById($id);
$car->getOwner()->getName();
$car->getOwner()->getId(); /** returns UUID */
From what I understand, It returns a string because doctrine will create a 'proxy' with the id pre-filled until a property is accessed and the entity 'initialised'.
I could add the following in the getId() method:
if(is_string($this->id))
{
$this->id = UUID::fromString($this->id);
}
But this kinda beats the purpose of types.
So my questions are:
This code
$ids = []
Doctrine\ORM\EntityRepository::findBy([
'id' => $ids,
]);
in 1.4.2 version generates Array to string conversion Notice
in ...\Doctrine\DBAL\Driver\PDOStatement.php:105
Previous version 1.4.1 didn't results to Notice in this case.
This happens on 10.1.21-MariaDB with last Doctrine version.
I want ordered uuids on database to increase query performance, this can be achieved thanks to UuidBinaryOrderedTimeType but in the way you sacrifice the ability to manually query database by id field as it's a binary (creating a function feels as a horrible hack)
Could a non-binary ordered uuid type (UuidOrderedTimeType) be added?
Hello,
With Symfony 5, and Doctrine, I have this query :
`
return $this
->createQueryBuilder('forum', 'forum.id')
->select('
forum
')
->getQuery()
->getResult()
;
`
As you can see, the keys to my array are "forum.id".
When I use "uuid / UuidType" for my IDs, it works well: my table keys are uuid.
But when I use "uuid_binary / UuidBinaryType", my table keys are strange symbols :
b"³ ø«\x11\x1EJe¸+¤\fu\x19F" => App\Entity\Forum
b"\x03?ïå&ŽOŽ¹\x02ص\t\x1A" => App\Entity\Forum
Can you help me to fix this ?
I know I can do a foreach to define my keys myself but it's a shame
I like to do this:
/**
* @var int
*
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var \Ramsey\Uuid\Uuid
*
* @ORM\Column(type="uuid")
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")
*/
private $uuid;
But this is not possible. It will remove the AUTO_INCREMENT from the id
field. More info: http://stackoverflow.com/questions/13915944/two-generated-values-in-doctrine
So please add to documentation how to use it additionally to an id
field.
Dear value member,
On local
Using Symfony 4.0.2 after setting all thing goes well.
On cloud (using clever-cloud)
Class 'Ramsey\Uuid\Doctrine\UuidType' not found in /home/bas/app_dd12c7af-6c95-4761-8b5f-ccc3b06ff0ee/vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/Type.php:167
I missed some config ?
Please let me know if possible.
Hi
I want to get the UUID as a string from the result of a query executed through the query builder.
I use the following code:
$query = $this->createQueryBuilder('a')
->select('a.id AS id, at.name AS name')
...
The id
field is the UUID, declared as follows into the entity file:
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")
*/
private $id;
The query result returns the UUID as an object of type Uuid
. Is there any way to get directly the UUID as a string from the query builder result ?
Thanks!
There's an interesting article in Percona blog that claims that due to InnoDB's internals it prefers sequential primary keys rather than completely random ones so one can simply leverage features of time-based UUID v1 to improve InnoDB performance.
Do you think it would be useful to have another doctrine type that reorders UUID in the way described in the article? There's a downside, of course: this hacky way of representing a UUID is somewhat more complicated to deal with (migrating to another column type looks more painful, for example) but still, graphs the author drew look promising and the amount of code to implement it seems to be quite small. What's your opinion on adding it?
I have a Symfony project with a Doctrine entity that's using the Doctrine Tree Extension. It looks something like below. Note the use of the "uuid_binary_ordered_time" column type which is setup per the docs.
/**
* @ORM\Entity
* @Gedmo\Tree(type="nested")
*/
class Foo
{
**
* @ORM\Id
* @ORM\Column(type="uuid_binary_ordered_time", unique=true)
*/
protected $id;
/**
* @Gedmo\TreeParent
* @ORM\ManyToOne(targetEntity="Foo", inversedBy="children")
*/
private $parent = null;
/**
* @ORM\OneToMany(targetEntity="Foo", mappedBy="parent")
*/
private $children;
/**
* @ORM\ManyToOne(targetEntity="Foo")
*/
private $root;
/**
* @Gedmo\TreeLeft
* @ORM\Column(type="integer")
*/
private $lft = null;
/**
* @Gedmo\TreeRight
* @ORM\Column(type="integer")
*/
private $rgt = null;
__construct()
{
$this->id = Uuid\Uuid::uuid1();
$this->children = new ArrayCollection();
}
}
My test is simply persisting a single entity with no parent or children. I am seeing it insert the record setting the id
value to the generated UUID and $parent to NULL both as expected.
[2020-03-06 23:40:38] doctrine.DEBUG: INSERT INTO foo (lft, rgt, name, id) VALUES (?, ?, ?, ?) {"1":0,"2":0,"3":"EG","4":"[object] (Ramsey\\Uuid\\Uuid: \"cb3bd9a0-602d-11ea-bf3f-0242be8c6bde\")"} []
The INSERT is immediately followed by an UPDATE to set $root, $left, and $right.
[2020-03-06 23:40:38] doctrine.DEBUG: UPDATE foo SET root_id = ?, lft = 1, rgt = 2 WHERE id = ? ["[object] (Ramsey\\Uuid\\Uuid: \"cb3bfcb4-602d-11ea-982c-0242be8c6bde\")","[object] (Ramsey\\Uuid\\Uuid: \"cb3bfcb4-602d-11ea-982c-0242be8c6bde\")"] []
Trouble is, that UPDATE appears to match no existing records so the $root, $left, and $right values for the inserted record are wrong. (the tree extension's listener is not checking that effected-rows result so it proceeds without error.
Curiously, if I switch back to normal "uuid" as the column type, it works. If fails with "uuid_binary" too. I feel like I'm missing something obvious but have been staring at this for the better part of the day and don't see the issue. Is this a bug?
Hi,
Do you have any pointers on how to use uuid_binary in relations?
Specifically I have a many-to-many relation and want the collection to be indexed by the uuid. If I specify the index-by="id"
property the the collection key is binary:
Ideally the index should be the string representation of the uuid object as otherwise it is not easy to write methods to interact with the collection (e.g. a has($entity)
method on the relation)
The last release doesn't include the UuidGenerator. Is it possible to create a new release that includes it?
Thanks for the good job!
Sorry if this isn't the right place.
I'm using you Uuid class as an id on an entity and I'm trying to write a DQL query (trying to load sub entities in a single query) with the query builder, using the various find()/findBy() funcitons work fine, how ever if I try and use the uuid in setParameter with the type set to 'uuid_binary' I just get a 500 error for exhausted memory (I tried upping the limit to 2GB and it still happens).
$query = $this->getEntityManager()->createQuery('SELECT c,i FROM AppBundle:Cart c join c.items i where c.id = :id')->setParameter('id', $cartId, 'uuid_binary');
Where $cartID is an instance of Uuid, if I remove the type parameter Doctrine just sends 'Object(Ramsey\Uuid\Uuid)' as the parameter to the DB, if I change the parameter to Doctrine's built in object type it sends 'C:16:"Ramsey\Uuid\Uuid":36:{6eed93c9-abbb-4ce4-b497-654f6dcab8aa}' (which I would expect) but as son as its set to uuid_binary PHP just hits its memory limit.
Closest I've found searching is I should be using Type::getType('uuid_binary') but this just results in a "Warning: Illegal offset type in isset or empty" in hasType() of 'doctrine\dbal\lib\Doctrine\DBAL\Types\Type.php', but as none of the built in Doctrine types work with that either I assume that is an out dated method.
I'm using Symfony 3.0.3, and Doctrine 2.5.4.
I just found an unexpected behavior.
Route definition:
@Route("/view/{id}", defaults={"id" = null})
Generating path:
{{ path('app_default_view',{id:entity.id}) }}
The example result is ok. We have our UUID in path as parameter:
/view/cf14f49a-e7b2-49ce-b561-84658850ea3b
Route definition:
@Route("/add")
Generating path:
{{ path('app_default_add',{parent:entity.id}) }}
The example result is:
/add
But expected result is:
/add?parent=cf14f49a-e7b2-49ce-b561-84658850ea3b
I just figured out that it works fine when I converting UUID object to string first while generating path:
{{ path('app_default_add',{parent:entity.id|trim}) }}
Now it works fine:
/add?parent=cf14f49a-e7b2-49ce-b561-84658850ea3b
✌️
I've just found an error when trying to use this library with Doctrine DBAL 2.4.4:
PHP Fatal error: Call to undefined method Doctrine\DBAL\Platforms\MySqlPlatform::getBinaryTypeDeclarationSQL() in /vendor/ramsey/uuid-doctrine/src/UuidBinaryType.php on line 43
Seems like that method is available from version 2.5 of DBAL.
Hey,
Before, i like your lib ❤️ .
If i use uuid with no dash, your validation throw error.
Your pattern is : ^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$
With no dash, your pattern is wrong. To Work you need "?" after dash.
Thanks for you job.
BR
I have the following use case: An entity with SomeID
as it's primary key. Internally, that id uses a uuid. I was hoping i could still use most of the types provided by this lib in the following way:
class SomeIdType extends UuidType
{
const NAME = 'some_id';
public function convertToPHPValue($value, AbstractPlatform $platform): ?SomeId
{
$uuid = parent::convertToPHPValue($value, $platform);
if (!$uuid) {
return null;
}
return new SomeId((string) $uuid);
}
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
{
return parent::convertToDatabaseValue((string) $value, $platform);
}
}
In both types, the name of the type is present as a constant. This constant is then used in the code as self::NAME
. This means that if you extend and override the constant, it has no effect.
In the current state, that means having to override the getName
method as well, which works but still leaves the ConversionException
with the wrong error message.
Would you consider changing it to static::NAME
? that way overriding the constant does have the desired effect or is there a specific reason it's using self::NAME
?.
Let me know if i should make a PR.
Hi,
I'm having a trouble. When I perform an persist() and flush() in Symfony, I'm getting this:
An exception occurred while executing 'INSERT INTO pedido (emissao, total, cliente_id) VALUES (?, ?, ?, ?)' with params ["2018-01-10", "100.00", "65c4002a-06e2-442b-b1da-61197f73ba3b"]:
SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value
My annotation is the same in all entities, but in this one (specifically), Doctrine can not create auto id:
/**
* @var \Ramsey\Uuid\Uuid
*
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")
*/
protected $id;
As the field ID is generated automatically, this error appears to make no sense.
How can I force Doctrine to "understand" the UUID field?
Hi. I'm having a problem with using findOneBy
doctrine method (MySQL).
The field uuid
in database is of type binary
and in ORM config the type is uuid_binary
.
Example:
$uuid = 'b154a022-e378-41ea-bf88-309da91e874d'; // Existed UUID value in the table
$person = $repository->findOneBy(['uuid' => $uuid]); // Returns null instead of existed data
From the logs I see that doctrine generates next query and it returns empty result:
SELECT t0.uuid AS uuid_1
FROM person t0
WHERE t0.uuid = '\xB1T\xA0\"\xE3xA꿈0\x9D\xA9�\x87M'
LIMIT 1
But, the query works if I use it like this:
SELECT t0.uuid AS uuid_1
FROM person t0
WHERE t0.`uuid` = x'b154a022e37841eabf88309da91e874d'
LIMIT 1
So, the question. How to use findOneBy
UUID method in doctrine in a proper way?
Although the Ramsey\Uuid library gives you full freedom to exchange generators and replace for example SystemNodeProvider with RandomNodeProvider, here you are doomed to default settings that use the passthru function, which is disabled on my server for security reasons.
The solution would be if you could set your own Factory, but at the moment it is not possible. The constructor is final private and the getUuidFactory method is private.
I know that you are trying to close objects to inappropriate changes, but could you do the getUuidFactory method at least protected? Many people work with this code in different environments and such restrictions can be frustrating.
I am trying to implement UUID on my Doctrine + Symfony project.. Here is a part of my code
<?php
/**
* @copyright 2016 Oversell. All rights reserved
* @author Oversell
*
* @link http://oversell.tk
*/
namespace CoreMarketplaceBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* StoreMonitoredProducts
*
* @ORM\Table(name="Ubersell.StoreMonitoredProducts", indexes={@ORM\Index(name="storeMonitoredProductId", columns={"storeMonitoredProductId"})})
* @ORM\Entity
*/
class StoreMonitoredProducts
{
/**
* @var \Ramsey\Uuid\Uuid
*
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")
*/
private $storeMonitoredProductId;
/**
* @var integer
*
* @ORM\Column(name="sourceMonitoredProductId", type="integer", nullable=false)
* @ORM\ManyToOne(targetEntity="SourceMonitoredProducts")
* @ORM\JoinColumn(name="sourceMonitoredProductId", referencedColumnName="sourceMonitoredProductId")
*/
private $sourceMonitoredProductId;
/**
* @var \Ramsey\Uuid\Uuid
*
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")
*/
private $apiAccessId;
/**
* @var integer
*
* @ORM\Column(name="marketplaceId", type="integer", nullable=false)
*/
private $dropMarketplaceId;
/**
* @var string
*
* @ORM\Column(name="siteId", type="string", nullable=false)
*/
private $dropSiteId;
/**
* @var string
*
* @ORM\Column(name="itemName", type="string", nullable=false)
*/
private $itemName;
/**
* @var integer
*
* @ORM\Column(name="quantity", type="integer", nullable=false)
*/
private $dropQuantity = 0;
/**
* @var double
*
* @ORM\Column(name="price", type="decimal", precision=12, scale=2, nullable=false)
*/
private $dropPrice = 0;
/**
* @var integer
*
* @ORM\Column(name="category", type="integer", nullable=false)
*/
private $dropCategory;
/**
* @var double
*
* @ORM\Column(name="breakEven", type="decimal", precision=4, scale=2, nullable=false)
*/
private $breakEven = 21;
/**
* @var double
*
* @ORM\Column(name="desiredProfit", type="decimal", precision=4, scale=2, nullable=false)
*/
private $desiredProfit = 10;
/**
* @var \DateTime
*
* @ORM\Column(name="lastUpdate", type="datetime", nullable=true)
*/
private $lastUpdate;
/**
* @var \Ramsey\Uuid\Uuid
*
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")
*/
private $productDataId;
/**
* @var double
*
* @ORM\Column(name="profit", type="decimal", precision=10, scale=2, nullable=false)
*/
private $profit = 0;
/**
* @var integer
*
* @ORM\Column(name="views", type="integer", nullable=false)
*/
private $views = 0;
/**
* @var integer
*
* @ORM\Column(name="watchers", type="integer", nullable=false)
*/
private $watchers = 0;
/**
* @var integer
*
* @ORM\Column(name="sold", type="integer", nullable=false)
*/
private $sold = 0;
/**
* @var double
*
* @ORM\Column(name="sellingRatio", type="decimal", precision=5, scale=2, nullable=false)
*/
private $sellingRatio = 0;
/**
* @return \Ramsey\Uuid\Uuid
*/
public function getStoreMonitoredProductId()
{
return $this->storeMonitoredProductId;
}
/**
* @param \Ramsey\Uuid\Uuid $storeMonitoredProductId
*
* @return StoreMonitoredProducts
*/
public function setStoreMonitoredProductId(\Ramsey\Uuid\Uuid $storeMonitoredProductId)
{
$this->storeMonitoredProductId = $storeMonitoredProductId;
return $this;
}
/**
* @return int
*/
public function getSourceMonitoredProductId()
{
return $this->sourceMonitoredProductId;
}
/**
* @param int $sourceMonitoredProductId
*
* @return StoreMonitoredProducts
*/
public function setSourceMonitoredProductId($sourceMonitoredProductId)
{
$this->sourceMonitoredProductId = $sourceMonitoredProductId;
return $this;
}
/**
* @return \Ramsey\Uuid\Uuid
*/
public function getApiAccessId()
{
return $this->apiAccessId;
}
/**
* @param \Ramsey\Uuid\Uuid $apiAccessId
*
* @return StoreMonitoredProducts
*/
public function setApiAccessId(\Ramsey\Uuid\Uuid $apiAccessId)
{
$this->apiAccessId = $apiAccessId;
return $this;
}
/**
* @return int
*/
public function getDropMarketplaceId()
{
return $this->dropMarketplaceId;
}
/**
* @param int $dropMarketplaceId
*
* @return StoreMonitoredProducts
*/
public function setDropMarketplaceId($dropMarketplaceId)
{
$this->dropMarketplaceId = $dropMarketplaceId;
return $this;
}
/**
* @return string
*/
public function getDropSiteId()
{
return $this->dropSiteId;
}
/**
* @param string $dropSiteId
*
* @return StoreMonitoredProducts
*/
public function setDropSiteId($dropSiteId)
{
$this->dropSiteId = $dropSiteId;
return $this;
}
/**
* @return string
*/
public function getItemName()
{
return $this->itemName;
}
/**
* @param string $itemName
*
* @return StoreMonitoredProducts
*/
public function setItemName($itemName)
{
$this->itemName = $itemName;
return $this;
}
/**
* @return int
*/
public function getDropQuantity()
{
return $this->dropQuantity;
}
/**
* @param int $dropQuantity
*
* @return StoreMonitoredProducts
*/
public function setDropQuantity($dropQuantity)
{
$this->dropQuantity = $dropQuantity;
return $this;
}
/**
* @return float
*/
public function getDropPrice()
{
return $this->dropPrice;
}
/**
* @param float $dropPrice
*
* @return StoreMonitoredProducts
*/
public function setDropPrice($dropPrice)
{
$this->dropPrice = $dropPrice;
return $this;
}
/**
* @return int
*/
public function getDropCategory()
{
return $this->dropCategory;
}
/**
* @param int $dropCategory
*
* @return StoreMonitoredProducts
*/
public function setDropCategory($dropCategory)
{
$this->dropCategory = $dropCategory;
return $this;
}
/**
* @return float
*/
public function getBreakEven()
{
return $this->breakEven;
}
/**
* @param float $breakEven
*
* @return StoreMonitoredProducts
*/
public function setBreakEven($breakEven)
{
$this->breakEven = $breakEven;
return $this;
}
/**
* @return float
*/
public function getDesiredProfit()
{
return $this->desiredProfit;
}
/**
* @param float $desiredProfit
*
* @return StoreMonitoredProducts
*/
public function setDesiredProfit($desiredProfit)
{
$this->desiredProfit = $desiredProfit;
return $this;
}
/**
* @return mixed
*/
public function getLastUpdate()
{
return $this->lastUpdate;
}
/**
* @param mixed $lastUpdate
*
* @return StoreMonitoredProducts
*/
public function setLastUpdate($lastUpdate)
{
$this->lastUpdate = $lastUpdate;
return $this;
}
/**
* @return \Ramsey\Uuid\Uuid
*/
public function getProductDataId()
{
return $this->productDataId;
}
/**
* @param \Ramsey\Uuid\Uuid $productDataId
*
* @return StoreMonitoredProducts
*/
public function setProductDataId(\Ramsey\Uuid\Uuid $productDataId)
{
$this->productDataId = $productDataId;
return $this;
}
/**
* @return float
*/
public function getProfit()
{
return $this->profit;
}
/**
* @param float $profit
*
* @return StoreMonitoredProducts
*/
public function setProfit($profit)
{
$this->profit = $profit;
return $this;
}
/**
* @return int
*/
public function getViews()
{
return $this->views;
}
/**
* @param int $views
*
* @return StoreMonitoredProducts
*/
public function setViews($views)
{
$this->views = $views;
return $this;
}
/**
* @return int
*/
public function getWatchers()
{
return $this->watchers;
}
/**
* @param int $watchers
*
* @return StoreMonitoredProducts
*/
public function setWatchers($watchers)
{
$this->watchers = $watchers;
return $this;
}
/**
* @return int
*/
public function getSold()
{
return $this->sold;
}
/**
* @param int $sold
*
* @return StoreMonitoredProducts
*/
public function setSold($sold)
{
$this->sold = $sold;
return $this;
}
/**
* @return float
*/
public function getSellingRatio()
{
return $this->sellingRatio;
}
/**
* @param float $sellingRatio
*
* @return StoreMonitoredProducts
*/
public function setSellingRatio($sellingRatio)
{
$this->sellingRatio = $sellingRatio;
return $this;
}
}
for some reason I get the following exception:
Entity 'CoreMarketplaceBundle\\Entity\\StoreMonitoredProducts' has a composite identifier but uses an ID generator other than manually assigning (Identity, Sequence). This is not supported.
When I removed the:
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")
parts from my UUID fields it seem to work but I am not sure if that is the correct way.. given what the introduction page tells us to do, and I get the following output (this is a json object of the entity):
{
"status": "success",
"data": [
{
"storeMonitoredProductId": {
"factory": {
"codec": {
"builder": {
"converter": {}
}
},
"nodeProvider": {
"nodeProviders": [
{},
{}
]
},
"numberConverter": {},
"randomGenerator": {},
"timeGenerator": {
"nodeProvider": {
"nodeProviders": [
{},
{}
]
},
"timeConverter": {},
"timeProvider": {}
},
"uuidBuilder": {
"converter": {}
}
},
"codec": {
"builder": {
"converter": {}
}
},
"fields": {
"time_low": "00532d60",
"time_mid": "6a9c",
"time_hi_and_version": "58b4",
"clock_seq_hi_and_reserved": "c9",
"clock_seq_low": "e7",
"node": "c566472cfc4c"
},
"converter": {}
},
"sourceMonitoredProductId": {
"factory": {
"codec": {
"builder": {
"converter": {}
}
},
"nodeProvider": {
"nodeProviders": [
{},
{}
]
},
"numberConverter": {},
"randomGenerator": {},
"timeGenerator": {
"nodeProvider": {
"nodeProviders": [
{},
{}
]
},
"timeConverter": {},
"timeProvider": {}
},
"uuidBuilder": {
"converter": {}
}
},
"codec": {
"builder": {
"converter": {}
}
},
"fields": {
"time_low": "3fb56ce4",
"time_mid": "116e",
"time_hi_and_version": "4b74",
"clock_seq_hi_and_reserved": "1d",
"clock_seq_low": "c3",
"node": "55cb537ff992"
},
"converter": {}
},
"apiAccessId": {
"factory": {
"codec": {
"builder": {
"converter": {}
}
},
"nodeProvider": {
"nodeProviders": [
{},
{}
]
},
"numberConverter": {},
"randomGenerator": {},
"timeGenerator": {
"nodeProvider": {
"nodeProviders": [
{},
{}
]
},
"timeConverter": {},
"timeProvider": {}
},
"uuidBuilder": {
"converter": {}
}
},
"codec": {
"builder": {
"converter": {}
}
},
"fields": {
"time_low": "00838830",
"time_mid": "4405",
"time_hi_and_version": "2de4",
"clock_seq_hi_and_reserved": "8d",
"clock_seq_low": "d3",
"node": "a4809a2fe56d"
},
"converter": {}
},
"dropMarketplaceId": 2,
"dropMarketplaceName": "ebay",
"dropSiteId": "110185928902",
"itemName": "TP Link",
"dropQuantity": 1,
"dropPrice": "20.00",
"breakEven": "21",
"desiredProfit": "25",
"lastUpdate": null,
"sourceMarketplaceId": 1,
"sourceMarketplaceName": "amazon",
"sourceSiteId": "B01AK9TC0Y",
"sourceQuantity": 1,
"sourcePrice": "198.19",
"lastScan": null,
"profit": "0.00",
"views": 0,
"watchers": 0,
"sold": 0,
"sellingRatio": "0.00"
},
{
"storeMonitoredProductId": {
"factory": {
"codec": {
"builder": {
"converter": {}
}
},
"nodeProvider": {
"nodeProviders": [
{},
{}
]
},
"numberConverter": {},
"randomGenerator": {},
"timeGenerator": {
"nodeProvider": {
"nodeProviders": [
{},
{}
]
},
"timeConverter": {},
"timeProvider": {}
},
"uuidBuilder": {
"converter": {}
}
},
"codec": {
"builder": {
"converter": {}
}
},
"fields": {
"time_low": "00580116",
"time_mid": "6965",
"time_hi_and_version": "79d4",
"clock_seq_hi_and_reserved": "41",
"clock_seq_low": "8b",
"node": "a9ef9e948524"
},
"converter": {}
},
"sourceMonitoredProductId": {
"factory": {
"codec": {
"builder": {
"converter": {}
}
},
"nodeProvider": {
"nodeProviders": [
{},
{}
]
},
"numberConverter": {},
"randomGenerator": {},
"timeGenerator": {
"nodeProvider": {
"nodeProviders": [
{},
{}
]
},
"timeConverter": {},
"timeProvider": {}
},
"uuidBuilder": {
"converter": {}
}
},
"codec": {
"builder": {
"converter": {}
}
},
"fields": {
"time_low": "7dc36e1a",
"time_mid": "a6fc",
"time_hi_and_version": "4144",
"clock_seq_hi_and_reserved": "79",
"clock_seq_low": "f6",
"node": "022f6808de57"
},
"converter": {}
},
"apiAccessId": {
"factory": {
"codec": {
"builder": {
"converter": {}
}
},
"nodeProvider": {
"nodeProviders": [
{},
{}
]
},
"numberConverter": {},
"randomGenerator": {},
"timeGenerator": {
"nodeProvider": {
"nodeProviders": [
{},
{}
]
},
"timeConverter": {},
"timeProvider": {}
},
"uuidBuilder": {
"converter": {}
}
},
"codec": {
"builder": {
"converter": {}
}
},
"fields": {
"time_low": "00838830",
"time_mid": "4405",
"time_hi_and_version": "2de4",
"clock_seq_hi_and_reserved": "8d",
"clock_seq_low": "d3",
"node": "a4809a2fe56d"
},
"converter": {}
},
"dropMarketplaceId": 2,
"dropMarketplaceName": "ebay",
"dropSiteId": "110186189158",
"itemName": "Sandisk",
"dropQuantity": 1,
"dropPrice": "20.00",
"breakEven": "21",
"desiredProfit": "16",
"lastUpdate": null,
"sourceMarketplaceId": 1,
"sourceMarketplaceName": "amazon",
"sourceSiteId": "B00VXMY262",
"sourceQuantity": 1,
"sourcePrice": "32.14",
"lastScan": null,
"profit": "0.00",
"views": 0,
"watchers": 0,
"sold": 0,
"sellingRatio": "0.00"
}
],
"draw": 3,
"recordsTotal": 2,
"recordsFiltered": 2
}
can't I have only the UUID string? how do I make it work just like the intro page explains?
Thanks for the package Ramsey
All-in-the-title 😃
In Oracle for relationships OneToOne throw this error: oci_bind_by_name(): "Invalid variable used for bind"
It could be Solved:
return string in the "convertToPHPValue" at UuidType
Consider the following test case:
// tests/UuidBinaryOrderedTimeTypeTest.php
public function testGettersReturnSameValuesAfterDatabaseRoundtrip()
{
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');
$dbValue = $this->type->convertToDatabaseValue($uuid, $this->platform);
$rehydrated = $this->type->convertToPHPValue($dbValue, $this->platform);
// all of these assertions are passing
$this->assertEquals($uuid->getHex(), $rehydrated->getHex());
$this->assertEquals($uuid->toString(), $rehydrated->toString());
$this->assertEquals($uuid->jsonSerialize(), $rehydrated->jsonSerialize());
$this->assertEquals($uuid->getFieldsHex(), $rehydrated->getFieldsHex());
$this->assertEquals($uuid->getUrn(), $rehydrated->getUrn());
$this->assertEquals($uuid->serialize(), $rehydrated->serialize());
// except this one:
$this->assertEquals($uuid->getBytes(), $rehydrated->getBytes());
}
Here, I expect the Uuid object methods to return same values after database roundtrip ( = I expect storage to behave transparently, not changing any substantial behavior of the object). All of the getters do behave as I expect, except the getBytes
.
The cause of this is that the custom codec is being stored into rehydrated object.
To add to the peculiarity of this, if I do unserialize(serialize($rehydrated))
, getBytes
starts to return expected values, because custom codec gets dropped.
I think that UuidType could extend GuidType instead of Type.
It would save from re-declaring getSQLDeclaration
method.
Moreover, comment can be skipped when native uuid is supported.
This is rather a question than an issue:
I would like to use the 'ramsey/uuid-doctrine' plugin with Zend Framework 2 and Doctrine 2.
I cannot find sufficient information where to put the field type configuration as Doctrine 2 does not have a classic bootstrap.php within a ZF2 project setup.
The global, local and module config files in ZF2 are array structures which will not accept a field type configuration like shown in the readme.
Where should the following lines from the readme be placed within in the ZF2 project so that the field type 'uuid' is available?
\Doctrine\DBAL\Types\Type::addType('uuid', 'Ramsey\Uuid\Doctrine\UuidType');
$entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('uuid', 'uuid');
Source:
https://github.com/ramsey/uuid-doctrine/blob/master/README.md
Any help would be greatly appreciated!
Hi,
I'm trying to use uuid-doctrine to my table 'Chat'
config.yml:
doctrine:
dbal:
driver: pdo_pgsql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
mapping_types:
citext: string
types:
uuid: Ramsey\Uuid\Doctrine\UuidType
use Ramsey\Uuid\Uuid;
/**
* @var Uuid
*
* @ORM\Column(name="id", type="uuid")
* @ORM\Id
* @Expose
* @Groups({"api-add-chat","api-get-chat"})
*/
private $id;
I do not use the generated value.
/**
* Set Id
*
* @return Chat
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
public function getId()
{
return $this->id;
}
But, i don't understand why when i use queryBuilder, it returns an array
"id": {},
When i'm testing my request with command-line, it returns all data.
This is my table in postgres:
Column | Type | Modifiers | Storage | Stats target | Description
id | uuid | not null | plain | | (DC2Type:uuid)
Could you help me please?
Thk's
I'm using a uuid_binary field as primary key for a Doctrine Entity:
class Site
{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="UUID")
* @ORM\Column(type="uuid_binary")
*/
private $id;
...
}
I need to build a form for another entity which has that entity in a ManyToOne relation.
So I added, in my form builder, an EntityType as follows:
$builder->add('site')
Everything works, the HTML select has the uuids as keys, but when I submit the form I get this validation error:
Symfony\Component\Validator\ConstraintViolation
Object(Symfony\Component\Form\Form).children[site] = 4a41b3c4-4299-11e6-b562-fc3fdb5f816dCaused by:
Symfony\Component\Form\Exception\TransformationFailedException
Unable to reverse value for property path "site": The choice "4a41b3c4-4299-11e6-b562-fc3fdb5f816d" does not exist or is not uniqueCaused by:
Symfony\Component\Form\Exception\TransformationFailedException
The choice "4a41b3c4-4299-11e6-b562-fc3fdb5f816d" does not exist or is not unique
Any idea about how to solve this?
Our test environment uses SQLLite database. We are working on document management system, so there is a virtual filesystem structure (files, folders) stored in database.
There are File and Folder entities, primary keys are binary UUIDs. All our query fails in JOIN queries on SQLLite database. We have changed our mappings to plain UUIDs (strings). Everything works now.
Our first guess is that binary UUIDs can not be used with SQLLite.
We guess that some kind of solution would be to either fix SQLLite driver or fix mapping which should detect SQLLite environment and fall back to string UUID if SQLLite per se can not work with binary UUIDs.
If this can not be fixed, we believe that it would be quite useful to improve documentation and add section "Known issues" and explain this issue for SQLLite.
Thanks.
(I am very sorry for not doing extensive research on this theory - kinda swamped with work... sorry.... )
I just tried to move from "classic" uuid to binary one, following the README (using Symfony).
It was failing with exception Unknown column type "uuid" requested
.
I had to specify both uuid
and uuid_binary
types in dbal configuration, while the README is mentioning uuid_binary
only.
@ramsey ... Thanks for a great UUID library. Been using for a bit now (couple of different places). Was thinking I would need to write the doctrine bit myself so I was happier still to find you had already done it.
However, in your documentation you mentioned that the database would store the object as a char(36)
unless someone used the uuid_binary.
So I know Postgres (and I believe also MySQL) has a UUID database type for a column.
So as I am sitting here typing this out (using you as a rubber duckie) this may be better answered by Doctrine, but still think you may have an answer?
Are you configuring it to do the char(36)
or is that strictly a Doctrine GUID thing?
Hi guys,
I'm getting this error when I persist a new entity on my new laptop on Ubuntu 18.04 and PHP 7.4 (but not on my server with the same config or another laptop with Windows 10 and PHP7.4) :
Cannot access protected property Ramsey\\Uuid\\Uuid::$codec
I tried to update the libraries but it is not effective so I came here to see if anyone else getting this error and maybe how fix it.
Thanks you for your time, have a nice day and stay safe
EDIT : Sorry for not retesting it before I posted this issue but it's not working neither with W10, my server or my laptop
Hi! Would be cool to have __toString() function in UuidInterface, but version 4.x-dev of ramsey/uuid is not compatibile with current version ramsey/uuid-doctrine, I'm writing some extensions to Nette Framework and I'm using UuidInterface in functions (mainly exception messages, and I don't want to use toString() as it's deprecated), now I noticed IDE errors that __toString() method does not exist. I can use Uuid class instead, but UuidInterface gives user a more control.
I fully understand the scope of this repo is to provide support to doctrine for the ramsey component, however in the scope of doctrine and uuid generation alone it's not explicitly clear why this is required. Given a lot of articles point here without discussing the shortfalls of the native doctrine approach to uuid generation, Would you welcome a PR to the readme with a very brief clarification for the the uses cases of the package (using ramsey vs native uuid generation)?
The text would need to answer: what is the use case for this library over using the native uuid strategy?
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#identifier-generation-strategies
I can see that doctrine simply calls the underlying database implementation of UUID which in the common cases I've looked into seems to generate a version 1 UUID:
https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_uuid
https://www.postgresql.org/docs/9.4/static/uuid-ossp.html
I can see that might be sub optimal, but it isn't clear:
http://stackoverflow.com/questions/20342058/which-uuid-version-to-use
It might help people answer the question 'do I need to use this', which is the question I currently debating.
What's the supposed way of configuring UuidFactory
in UuidBinaryOrderedTimeType
? Unless I'm missing something, seems like the only way to do this is to copy-paste the whole class modifying uuidFactory init (because getUuidFactory
is private).
More specifically, I'd like to be able to provide a different implementation of NodeProviderInterface
(a cached SystemNodeProvider
)
I am running in some trouble with the implementation of this bundle in a legacy application. The uuid's where always used but not with this bundle.
I want to serialize some data that is being fetched using the querybuilder.
$datatable = $this->get('training.datatables.training');
$results = $datatable->createDatatable();
$serializer = $this->get('sg_datatables.serializer');
$datatable->setData($serializer->serialize($results, 'json'));
The serialize function throws this exception:
Could not normalize object of type Ramsey\Uuid\Converter\Number\DegradedNumberConverter, no supporting normalizer found.
500 Internal Server Error - UnexpectedValueException
I have tried to cast the id field to string in some hack, but even that does not work.
Am i missing something here or is this "by design"?
I am building a project management tool for my team in Symfony 3. I am using ramsey/uuid-doctrine for the IDs in the system. I'm betting this is a problem with Doctrine and not this library, but figured I would have better chance of finding someone who might be familiar with this problem here than if I filed a Doctrine issue. I also posted this question to StackOverflow and will close this issue if I get an answer there.
So far, this hasn't been a problem with One-to-Many or Many-to-One associations, but when I try to persist a One-to-One association, Doctrine is not converting the associated entity to its UUID, and instead leaving a null
value in the SQL.
In this example, I have a WikiPage which can have multiple WikiPageVersions. The WikiPage has a One-to-Many association with WikiPageVersion (the versions
property: for all the versions of the page), but also a One-to-One (Unidirectional) association with WikiPageVersion (the currentVersion
property: for the, well, current version).
The WikiPage also has a Many-to-One associations with Project (to track which project the wiki page is for) and that property is populated correctly.
The WikiPage Entity
/**
* @ORM\Table(name="wiki_page")
* @ORM\Entity(repositoryClass="AppBundle\Repository\Project\WikiPageRepository")
*/
class WikiPage
{
/**
* @var Uuid
* @ORM\Id
* @ORM\Column(type="uuid")
*/
protected $id;
/**
* @var Project
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Project\Project", inversedBy="wikiPages")
* @ORM\JoinColumn(name="project_id", referencedColumnName="id")
*/
protected $project;
/**
* @var string
* @ORM\Column(name="title", type="text")
* @Assert\NotBlank()
*/
protected $title;
/**
* @var HiveWikiPageVersion
* @ORM\OneToOne(targetEntity="AppBundle\Entity\Project\WikiPageVersion", fetch="EAGER")
*/
protected $currentVersion;
/**
* @var ArrayCollection
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Project\WikiPageVersion", mappedBy="wikiPage", cascade={"persist", "remove"})
*/
protected $versions;
// -- Class Methods
}
The WikiPageVersion Entity
/**
* @ORM\Table(name="wiki_page_version")
* @ORM\Entity(repositoryClass="AppBundle\Repository\Project\WikiPageVersionRepository")
*/
class WikiPageVersion
{
/**
* @var Uuid
* @ORM\Id
* @ORM\Column(type="uuid")
*/
protected $id;
/**
* @var WikiPage
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Project\WikiPage", inversedBy="versions")
* @ORM\JoinColumn(name="wiki_page_id", referencedColumnName="id")
* @Assert\NotBlank()
*/
protected $wikiPage;
/**
* @var string
* @ORM\Column(name="content", type="text")
* @Assert\NotBlank()
*/
protected $content;
/**
* @var string
* @ORM\Column(name="version_comment", type="string", length=255)
* @Assert\NotNull()
*/
protected $versionComment;
/**
* @var HiveWikiPageVersion
* @ORM\OneToOne(targetEntity="AppBundle\Entity\Project\WikiPageVersion")
* @ORM\JoinColumn(name="previous_version", referencedColumnName="id")
* @Assert\Type(type="Odev\Hive\Model\Entity\Project\WikiPageVersion")
*/
protected $previousVersion;
/**
* @var \DateTimeInterface
* @ORM\Column(name="created", type="datetime")
* @Assert\NotBlank()
*/
protected $created;
/**
* @var User
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User")
* @ORM\JoinColumn(name="created_by", referencedColumnName="id")
* @Assert\NotBlank()
*/
protected $createdBy;
}
// -- Methods
Here is the error I get from Doctrine when I try to perist the WikiPage:
[Doctrine\DBAL\Exception\NotNullConstraintViolationException]
An exception occurred while executing 'INSERT INTO wiki_page (id, project_home, title, project_id, current_version_id) VALUES (?, ?, ?, ?, ?)' with params ["ddc1f51a-f5d9-489f-89bb-cd79f3393af0", 1
, "Technical Reviews Wiki", "5138b185-b10b-48ac-a102-bdea1139c911", null]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'current_version_id' cannot be null
and the exception trace (this exception is from saving during fixtures loading):
Exception trace:
() at /home/vagrant/hive/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:112
Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException() at /home/vagrant/hive/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:128
Doctrine\DBAL\DBALException::driverExceptionDuringQuery() at /home/vagrant/hive/vendor/doctrine/dbal/lib/Doctrine/DBAL/Statement.php:177
Doctrine\DBAL\Statement->execute() at /home/vagrant/hive/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php:281
Doctrine\ORM\Persisters\Entity\BasicEntityPersister->executeInserts() at /home/vagrant/hive/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1014
Doctrine\ORM\UnitOfWork->executeInserts() at /home/vagrant/hive/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:378
Doctrine\ORM\UnitOfWork->commit() at /home/vagrant/hive/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:356
Doctrine\ORM\EntityManager->flush() at /home/vagrant/hive/src/Odev/Hive/Infrastructure/AppBundle/DataFixtures/ORM/LoadProjectData.php:89
Odev\Hive\Infrastructure\AppBundle\DataFixtures\ORM\LoadProjectData->load() at /home/vagrant/hive/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Executor/AbstractExecutor.php:121
Doctrine\Common\DataFixtures\Executor\AbstractExecutor->load() at /home/vagrant/hive/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Executor/ORMExecutor.php:88
Doctrine\Common\DataFixtures\Executor\ORMExecutor->Doctrine\Common\DataFixtures\Executor\{closure}() at n/a:n/a
call_user_func() at /home/vagrant/hive/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:233
Doctrine\ORM\EntityManager->transactional() at /dev/shm/app/cache/dev/appDevDebugProjectContainer.php:5645
DoctrineORMEntityManager_00000000015ce1f5000000002a2c79364ae5d79093a662a969d1540330e84087->transactional() at /home/vagrant/hive/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Executor/ORMExecutor.php:90
Doctrine\Common\DataFixtures\Executor\ORMExecutor->execute() at /home/vagrant/hive/vendor/doctrine/doctrine-fixtures-bundle/Command/LoadDataFixturesDoctrineCommand.php:118
Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand->execute() at /home/vagrant/hive/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:262
Symfony\Component\Console\Command\Command->run() at /home/vagrant/hive/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:848
Symfony\Component\Console\Application->doRunCommand() at /home/vagrant/hive/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:189
Symfony\Component\Console\Application->doRun() at /home/vagrant/hive/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:80
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /home/vagrant/hive/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:120
Symfony\Component\Console\Application->run() at /home/vagrant/hive/bin/console:29
At this point I am lost - if there is any suggestions of where I should be looking or if anyone else has run into this problem, I would love and guidance that could be provided.
Hi.
After reading your post about Uuids:UuiDs, I installed your package.
"My" EntityIdTrait is yours.
My (unique) entity starts with:
class Deuda
{
use EntityIdTrait;
/**
* @var UuidInterface
*
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")
*/
private $id;
/**
* The internal primary identity key.
*
* @var UuidInterface|null
*
* @ORM\Column(type="uuid", unique=true)
*/
protected $uuid;
// The rest of the file contains boring getters and setters and more fields
I also updated the config/packages/doctrine.yaml file:
types:
uuid: Ramsey\Uuid\Doctrine\UuidType
After these changes, I got this message:
When I run my SF4 app, I got this message:
Symfony version: 4.x.x
What's wrong?
Kindest regards
Hi there, could be safe to upgrade the doctrine requirement to 2.6?
Hi,
I'm using the UuidBinaryOrderedTimeType as PK on my tables. Beside the benefits mentioned in the documentation regarding speed and (index) sizes, it also allows me to easily order results by the timestamp embedded in the uuid 🎉 . This got me thinking, is it also possible to query for these timestamps? For example: I'd like all records in a table with a UUID/PK generated before or after a particular moment.
Thanks!
Hello :)
I use Symfony 5, Doctrine, MySQL 8 and Ramsey uuid-doctrine.
This is my ID Forum
entity :
`
/**
* @var \Ramsey\Uuid\UuidInterface
*
* @ORM\Id
* @ORM\Column(type="uuid_binary_ordered_time", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidOrderedTimeGenerator")
*/
private $id;
`
I have this method on my repository :
`
public function findById(string $forumId): ?Forum
{
return $this
->createQueryBuilder('forum')
->andWhere('forum.id = :forumId')
->setParameter('forumId', $forumId)
->select('
forum
')
->getQuery()
->getOneOrNullResult()
;
}
`
Now I want to retrieve this forum using the method findById()
(with paremeters url, /forums/{uuid}/).
But these tests return null :
`
findById('37b3c336-4b4d-11ea-ab15-309c23145bb0');
findById(Uuid::fromString('37b3c336-4b4d-11ea-ab15-309c23145bb0'));
findById(Uuid::fromString('37b3c336-4b4d-11ea-ab15-309c23145bb0')->getBytes());
`
Thanks very much for your help
I have a field that is uuid, when I search this field with an invalid uuid (a string), it throws a ConversionException, but I was expecting database gives me a not found and return null.
Is there any advantage having this exception?
The situation is that doctrine cant resolve relations.
I have an entities:
Entity_1:
type: entity
id:
uuid:
type: uuid_binary
unique: true
generator:
strategy: CUSTOM
customIdGenerator:
class: '\Ramsey\Uuid\Doctrine\UuidGenerator'
`
Entity_2:
id:
uuid:
type: uuid_binary
unique: true
generator:
strategy: CUSTOM
customIdGenerator:
class: '\Ramsey\Uuid\Doctrine\UuidGenerator'
manyToOne:
owner:
targetEntity: Entity_1
cascade: { }
fetch: LAZY
mappedBy: null
inversedBy: null
joinColumns:
owner_id:
referencedColumnName: uuid
orphanRemoval: false
lifecycleCallbacks: { }
And querybuilder:
$qb->where('s.owner = :owner') ->addOrderBy('s.created', 'DESC') ->setMaxResults(1) ->setParameter('owner', $owner);
In logs i see, that this query has not resolved to correct view, now its looks like
FROM entity_2 e0_ WHERE e0_.owner_id = 'Object(Ramsey\\Uuid\\Uuid)'
and not like i expect
FROM entity_2 e0_ WHERE e0_.owner_id ='3b0b36c5ba224582bbb3dfacbf96fcd7'
I found only 1 solution:
public function getUuid() { return $this->uuid->getBytes(); }
... ->setParameter('owner', $owner->getUuid())
But this solution does not suit me for architectural requirements
Then I create entity with you uuid type, for every use Doctrine schema tools generates this king of "update" SQL:
ALTER TABLE table ALTER id_table TYPE UUID;
ALTER TABLE table ALTER id_table DROP DEFAULT;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.