Bug in AssignedGenerator.php #5296

Open
opened 2026-01-22 15:03:54 +01:00 by admin · 5 comments
Owner

Originally created by @janelletavares on GitHub (Oct 18, 2016).

I believe that I found a bug in the latest version of AssignedGenerator.php.

- $value = $em->getUnitOfWork()->getSingleIdentifierValue($value);
+ $value = $em->getUnitOfWork()->getSingleIdentifierValue($entity);

getSingleIdentifierValue is expecting an entity. When you pass a value into getSingleIdentifierValue and not an entity, the get_class() function does not return a coherent value. A type hint, if that is possible, would help. In my case, get_class() has been returning an empty string. Eventually, the code throws a MappingException::nonExistingClass exception.

Here's generally what I was doing when I reproduced it.

class MyStuff {
  /*
   * @Id @Column(type="string", length=255, unique=true)
   */
  private $key;

  /*
   * @ManyToOne(targetEntity="YourStuff")
   *
   * @Id @Column(type="string", nullable=false, length=255)
   *
   * @JoinColumn(name="name_join", referencedColumnName="key")
   */
  private $foreign_key;
}

class YourStuff {
  /*
   * @Id @Column(type="string", length=255, unique=true)
   */
  private $key;
}
Originally created by @janelletavares on GitHub (Oct 18, 2016). I believe that I found a bug in the latest version of AssignedGenerator.php. ``` diff - $value = $em->getUnitOfWork()->getSingleIdentifierValue($value); + $value = $em->getUnitOfWork()->getSingleIdentifierValue($entity); ``` `getSingleIdentifierValue` is expecting an entity. When you pass a value into `getSingleIdentifierValue` and not an entity, the get_class() function does not return a coherent value. A type hint, if that is possible, would help. In my case, get_class() has been returning an empty string. Eventually, the code throws a `MappingException::nonExistingClass` exception. Here's generally what I was doing when I reproduced it. ``` PHP class MyStuff { /* * @Id @Column(type="string", length=255, unique=true) */ private $key; /* * @ManyToOne(targetEntity="YourStuff") * * @Id @Column(type="string", nullable=false, length=255) * * @JoinColumn(name="name_join", referencedColumnName="key") */ private $foreign_key; } class YourStuff { /* * @Id @Column(type="string", length=255, unique=true) */ private $key; } ```
admin added the BugMissing Tests labels 2026-01-22 15:03:54 +01:00
Author
Owner

@Ocramius commented on GitHub (Oct 18, 2016):

@janelletavares can you please try reproducing this in a test case? See d3f6c5ec70/tests/Doctrine/Tests/ORM/Functional/Ticket for examples

@Ocramius commented on GitHub (Oct 18, 2016): @janelletavares can you please try reproducing this in a test case? See https://github.com/doctrine/doctrine2/tree/d3f6c5ec70aac4b029a4b61ecf1e2ba61a1a4a6d/tests/Doctrine/Tests/ORM/Functional/Ticket for examples
Author
Owner

@janelletavares commented on GitHub (Oct 18, 2016):

I'm not sure when I will have time to do that, but I will keep it on my ToDo list.

@janelletavares commented on GitHub (Oct 18, 2016): I'm not sure when I will have time to do that, but I will keep it on my ToDo list.
Author
Owner

@fezfez commented on GitHub (Jan 25, 2018):

big todo list

@fezfez commented on GitHub (Jan 25, 2018): big todo list
Author
Owner

@Ocramius commented on GitHub (Jan 26, 2018):

@fezfez pretty much like everyone. Indeed, without a test we can't do much about this issue.

@Ocramius commented on GitHub (Jan 26, 2018): @fezfez pretty much like everyone. Indeed, without a test we can't do much about this issue.
Author
Owner

@fezfez commented on GitHub (Jan 26, 2018):

@Ocramius : yeah i know, i was searching docs for AssignedGenerator and i found this issue. the reponse from @janelletavares has more than one year, i just laught about how big his todo list must be.

No offense and thanks for your work ! ❤️

@fezfez commented on GitHub (Jan 26, 2018): @Ocramius : yeah i know, i was searching docs for AssignedGenerator and i found this issue. the reponse from @janelletavares has more than one year, i just laught about how big his todo list must be. No offense and thanks for your work ! ❤️
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5296