This is a follow-up to a question previously opened, refer to the link
I am using, symfony2 donctrine , inside about the database operation, all used entities, the official recommendation to establish the relationship between table and table, I made some changes, I found an entity can not set two many-to-one relationship, the following is the description and reproduction of the problem:
In view of the previous question people do not recommend the use of physical external health, I have done some procedural aspects of processing:
Delete Data sheet physical external health;
Set the corresponding entity relationship in the program;
Simple ER diagram update:
The Commodity Attribute Association table goods_and_attribute is relative to the commodity table goods and is a attributes many-to-one relationship, so I add the following program to the entity file:
#src/AppBundle/Resources/config/doctrine/GoodsAndAttribute.orm.ymlAppBundle\Entity\GoodsAndAttribute: type: entity table: goods_and_attribute id: ... fields: ... manyToOne: goods: targetEntity: Goods inversedBy: goodsAndAttribute joinColumn: name: goods_id referencedColumnName: id manyToOne: attribute: targetEntity: Attributes inversedBy: goodsAndAttribute joinColum: name: attribute_id referencedColumnName: id lifecycleCallbacks: { }
When querying the data table, I found that I could only get information about one of the relationships:
$query = $em ->createQuery( 'SELECT ga FROM AppBundle:GoodsAndAttribute ga WHERE ga.id = 1');
ormHow do I correlate multiple tables in the query for the corresponding information? For example
$query = $em ->createQuery( 'SELECT ga, g, a FROM ApplicationSonataMallBundle:GoodsAndAttribute ga JOIN ga.goods g JOIN ga.attribute a WHERE ga.id = 1');
Reply content:
This is a follow-up to a question previously opened, refer to the link
I am using, symfony2 donctrine , inside about the database operation, all used entities, the official recommendation to establish the relationship between table and table, I made some changes, I found an entity can not set two many-to-one relationship, the following is the description and reproduction of the problem:
In view of the previous question people do not recommend the use of physical external health, I have done some procedural aspects of processing:
Delete Data sheet physical external health;
Set the corresponding entity relationship in the program;
Simple ER diagram update:
The Commodity Attribute Association table goods_and_attribute is relative to the commodity table goods and is a attributes many-to-one relationship, so I add the following program to the entity file:
#src/AppBundle/Resources/config/doctrine/GoodsAndAttribute.orm.ymlAppBundle\Entity\GoodsAndAttribute: type: entity table: goods_and_attribute id: ... fields: ... manyToOne: goods: targetEntity: Goods inversedBy: goodsAndAttribute joinColumn: name: goods_id referencedColumnName: id manyToOne: attribute: targetEntity: Attributes inversedBy: goodsAndAttribute joinColum: name: attribute_id referencedColumnName: id lifecycleCallbacks: { }
When querying the data table, I found that I could only get information about one of the relationships:
$query = $em ->createQuery( 'SELECT ga FROM AppBundle:GoodsAndAttribute ga WHERE ga.id = 1');
ormHow do I correlate multiple tables in the query for the corresponding information? For example
$query = $em ->createQuery( 'SELECT ga, g, a FROM ApplicationSonataMallBundle:GoodsAndAttribute ga JOIN ga.goods g JOIN ga.attribute a WHERE ga.id = 1');