Orm: Single id is not allowed on composite primary key in entity

Created on 13 Mar 2017  路  4Comments  路  Source: doctrine/orm

I have same issue as described in this question.

Can't use composite keys in entity, while having one of them being auto-generated.

For example:

/**
 * @Entity
 */
class User
{
    /**
      * @Id
      * @Column(type="integer")
      */
    private $foo;

    /**
      * @Id
      * @Column(type="integer")
      */
    private $bar;
}

This will work until I add @GeneratedValue() on one of them.

Thanks.

Can't Fix Improvement Question Won't Fix

All 4 comments

Multi-column composite identifiers are not supported, and are going to stay like that for a while, since we didn't figure out how to properly handle them. A custom identifier generator strategy would be preferrable on your side.

Closing as won't fix

@Ocramius Could you explain what the issue/limitation is ?

The problem is that the UnitOfWork and many other internal components assume that an identifier is either generated or not: we don't have a concept in between. I know @guilhermeblanco did some work on this for 3.x, but I don't know how far he got.

You need to remove all @Id in properties description except protected $id.

Was this page helpful?
0 / 5 - 0 ratings