Orm: Using two sequences in the same table

Created on 4 May 2017  路  4Comments  路  Source: doctrine/orm

I need to handle two sequences for the same table like this:

class Foo
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="SEQUENCE")
     * @SequenceGenerator(sequenceName="a_seq")
     */
    private $a;

    /**
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="SEQUENCE")
     * @SequenceGenerator(sequenceName="b_seq")
     */
    private $b;
}

But insert has failed with not null violation on "b".
A query looks like INSERT INTO foo (a, b) VALUES (42, null).
My DDL allow usingDEFAULT nextval('b_seq'::regclass);, but Doctrine pass null explicit and breaks query.
How can I avoid them?

Improvement Question

Most helpful comment

This should be possible in develop (maybe not just yet, but the code is ready for this) -- thus adding to 3.0 backlog and removing wontfix, and we shall see how this goes. :)

All 4 comments

This is not supported, as the ORM will only read a single insert identifier each time. It's a known limitation, and it also isn't possible to mix auto-incremental/sequence fields with assigned fields at the moment.

Maybe is there some hack with metadata or another 'hacky' way to use them?

@sc0rp10 no, the limitation is in the persisters

This should be possible in develop (maybe not just yet, but the code is ready for this) -- thus adding to 3.0 backlog and removing wontfix, and we shall see how this goes. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

doctrinebot picture doctrinebot  路  4Comments

dmaicher picture dmaicher  路  3Comments

Inmmelman picture Inmmelman  路  3Comments

strayobject picture strayobject  路  4Comments

doctrinebot picture doctrinebot  路  4Comments