How do I use the doctrine ORM to implement two foreign key settings on a single table in a program logic (or does an entity complete two many-to-one relationships)?
Source: Internet
Author: User
KeywordsPhpsymfonydoctrine2mysql
This is a follow-up to a question previously opened, refer to the link
I am using, symfony2donctrine , 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:
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, symfony2donctrine , 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:
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');
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.