2015-12-20 2 views
3

Решающий объект «производитель» объекта, который включает массив с переводами, принадлежащими этому объекту.Ссылки на привязку ссылок на YML

Сохранение базы данных для достижения успеха. Однако в таблице, содержащей переводы, отсутствует ссылка на таблицу «производитель».

Этот результат:

my_producer:

+----+----+ 
| id |code| 
+----+----+ 
| 1 |abcd| 
+----+----+ 

my_producer_translations

+----+-----------+----+------+ 
| id |id_producer|name|locale| 
+----+-----------+----+------+ 
| 1 | NULL |abcd| en | 
+----+-----------+----+------+ 
| 2 | NULL |abcd| de | 
+----+-----------+----+------+ 

Сущность ProducerTranslation

ProducerTranslation 
{ 
    protected $id; 
    protected $name; 
    protected $producer; 
    protected $locale; 

    ... getters and setters 
} 

Сущность Производитель

Producer 
{ 
    protected $id; 
    protected $code; 
    protected $translations; 

    public function __construct() 
    { 
     $this->translations = new ArrayCollection; 
    } 

    ... getters and setters, method for adding translations (entity ProductTranslation) 
} 

Производитель YML

My\ProducerBundle\Entity\Producer: 
    type: entity 
    table: my_producer 
    id: 
    id: 
     type: integer 
     generator: 
     strategy: AUTO 
    fields: 
    code: 
     type: string 
     length: 50 
     nullable: true 

    oneToMany: 
    translations: 
     targetEntity: ProducerTranslation 
     mappedBy: producer 
     cascade: ["persist", "remove"] 

ProducerTranslation YML

My\ProducerBundle\Entity\ProducerTranslation: 
    type: entity 
    table: my_producer_translations 
    id: 
    id: 
     type: integer 
     generator: 
     strategy: AUTO 
    fields: 
    name: 
     type: string 
     length: 100 
    locale: 
     type: text 
     length: 2 

    manyToOne: 
    producer: 
     targetEntity: Producer 
     inversedBy: translations 
     joinColumn: 
     name: producer_id 
     referencedColumnName: id 
     onDelete: CASCADE 

ответ

2

Перед сохранить набор Producer в ProducerTranslation $ProducerTranslation->setProducer($Producer)
Почему вы позволили аннулирует для ProducerTranslation.id_producer?

Смежные вопросы