Reputation: 3657
I have been searching for the exact mappings for for the DB Schema as shown below
As one can see the product_i18n table has two composite foreign keys (product_id and locale_id).
Now once the product and locale entities are finished, I wanted to insert the data (name and description) into the product_i18n table.
Is there an example which is similar to this type of mapping using Doctrine 2. Or in case if some one can give a brief overview how to approach this type of mapping, then your information is appreciated.
P.S. In case if one requires more information regarding this, then please dont hesitate to ask.
Upvotes: 7
Views: 20211
Reputation: 14747
Doctrine 2 supports composite keys natively
/**
* @Entity
*/
class ProductI18N
{
/** @Id @Column(type="string") */
private $product;
/** @Id @Column(type="string") */
private $locale
public function __construct($product, $locale)
{
$this->product= $product;
$this->locale= $locale;
}
Always keep in mind that the composite key MUST be setted before persist the model:
$productI18N = new ProductI18N("Guanabana", "CR");
$em->persist($productI18N );
$em->flush();
For more information about you can see the documentation: http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/tutorials/composite-primary-keys.html
Upvotes: 13
Reputation: 476
If you have a composite key in with field 1 (id autoincrement) and the field 2 (specified) use:
class ProductI18N
{
/** @Id @Column(type="string") @GeneratedValue(strategy="AUTO") */
private $product;
/** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */
private $locale
Upvotes: 4