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
Keywords Php symfony doctrine2 mysql

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:

    1. Delete Data sheet physical external health;

    2. 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:

    1. Delete Data sheet physical external health;

    2. 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');
  • Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.