0

I have a Entity with composite keys. See below:

class BankAccount {

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * 
     */
    protected $bank;

    /**
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="CompanyBundle\Entity\Company")
     */
    protected $company;

    ...

}

because Doctrine has some issues with composite keys it won't generates sequences (I'm working in PostgreSQL), how do I deal with this in order to generate $bank which is the PK?

Reynier
  • 2,420
  • 11
  • 51
  • 91
  • I'm not sure if i understand your question - please clarify. you can't use `@ORM\GeneratedValue(strategy="AUTO")` for the primary key with postgresql and are looking for a way to generate the id ? – Nicolai Fröhlich Jul 31 '13 at 23:42

1 Answers1

1

If sounds like you don't want a composite key, just a primary key on $bank and a foreign key on $company. If that's the case,

class BankAccount {

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $bank;

    /**
     * @ORM\ManyToOne(targetEntity="CompanyBundle\Entity\Company")
     */
    protected $company;

    ...

}

should do it.

mattexx
  • 6,456
  • 3
  • 36
  • 47