Invalid multiple primary keys #6754

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

Originally created by @RSalo on GitHub (Jun 11, 2021).

Hello. I have 2 primary keys: ID and blob UUID. And have 2 entities User and Article. Then for Article i generate relation ManyToOne and have code:

class User
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="NONE")
     * @ORM\Column(type="uuid", unique=true, nullable=false)
     */
    private $uuid;

    /**
     * @ORM\OneToMany(targetEntity=Article::class, mappedBy="user",)
     */
    private $articles;
 }
class Article
{
    /**
     * @ORM\ManyToOne(targetEntity=User::class, inversedBy="articles")
     * @ORM\JoinColumn(nullable=false, referencedColumnName="uuid", name="user_uuid")
     */
    private $user;
}

Problem is that i have invalid mapping:

php bin/console doctrine:schema:validate   

Mapping
-------

 [FAIL] The entity-class App\Entity\Article mapping is invalid:
 * The join columns of the association 'user' have to match to ALL identifier columns of the target entity 'App\Entity\User', however 'id, uuid' are missing.


Database
--------

                                                                                                                        
 [OK] The database schema is in sync with the mapping files.                                                            
                                                                                                                        

Is it a bug or am I do something wrong? Thanks!

Originally created by @RSalo on GitHub (Jun 11, 2021). Hello. I have 2 primary keys: ID and blob UUID. And have 2 entities User and Article. Then for Article i generate relation ManyToOne and have code: ```PHP class User { /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @ORM\Id * @ORM\GeneratedValue(strategy="NONE") * @ORM\Column(type="uuid", unique=true, nullable=false) */ private $uuid; /** * @ORM\OneToMany(targetEntity=Article::class, mappedBy="user",) */ private $articles; } ``` ```PHP class Article { /** * @ORM\ManyToOne(targetEntity=User::class, inversedBy="articles") * @ORM\JoinColumn(nullable=false, referencedColumnName="uuid", name="user_uuid") */ private $user; } ``` Problem is that i have invalid mapping: ``` php bin/console doctrine:schema:validate Mapping ------- [FAIL] The entity-class App\Entity\Article mapping is invalid: * The join columns of the association 'user' have to match to ALL identifier columns of the target entity 'App\Entity\User', however 'id, uuid' are missing. Database -------- [OK] The database schema is in sync with the mapping files. ``` Is it a bug or am I do something wrong? Thanks!
Author
Owner

@RSalo commented on GitHub (Jun 11, 2021):

Similar to https://github.com/doctrine/orm/issues/4088

@RSalo commented on GitHub (Jun 11, 2021): Similar to https://github.com/doctrine/orm/issues/4088
Author
Owner

@dexy86 commented on GitHub (Nov 23, 2022):

Hello
@RSalo it is but again it isn't
in #4088 in both entities you have all the columns a bit different naming
but in this example you don't have same values in both entities
i have the same issue, and if i try to use JoinColumns with multiple columns i get an error which makes sense cause i don't have (e.g. uuid in both of the entities)

how can we do many2one or any other relations if you can't fetch by composite primary key if needed

i hope i have explained it correctly and pardon me if i am wrong 🙇

@dexy86 commented on GitHub (Nov 23, 2022): Hello @RSalo it is but again it isn't in [#4088](https://github.com/doctrine/orm/issues/4088) in both entities you have all the columns a bit different naming but in this example you don't have same values in both entities i have the same issue, and if i try to use JoinColumns with multiple columns i get an error which makes sense cause i don't have (e.g. uuid in both of the entities) how can we do many2one or any other relations if you can't fetch by composite primary key if needed i hope i have explained it correctly and pardon me if i am wrong :bow:
Author
Owner

@khal3d commented on GitHub (Sep 1, 2023):

Have you managed to resolve this issue? doctrine/orm v2.16.1 and I'm facing the same issue

@khal3d commented on GitHub (Sep 1, 2023): Have you managed to resolve this issue? doctrine/orm v2.16.1 and I'm facing the same issue
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6754