Home > Article > Backend Development > Detailed explanation of the method of implementing joint query in Symfony2
This article mainly introduces the implementation method of Symfony2 joint query, and briefly analyzes the specific steps and implementation techniques of Symfony2 joint query in the form of examples. Friends in need can refer to it. I hope it will be helpful to everyone.
1.yml file
Acme\MspadminBundle\Entity\MspArticle: type: entity table: msp_article manyToOne: Channel: targetEntity: MspChannel inversedBy: Articles joinColumn: name: channel_id referencedColumnName: channel_id User: targetEntity: MspUser inversedBy: Userone joinColumn: name: user_id referencedColumnName: user_id
Acme\MspadminBundle\Entity\MspChannel: type: entity table: msp_channel oneToMany: Articles: targetEntity: MspArticle mappedBy: Channel
Acme\MspadminBundle\Entity\MspUser: type: entity table: msp_user oneToMany: Userone: targetEntity: MspArticle mappedBy: User
2. Query code:
$sql="SELECT a.id,a.checkStatus,a.title,a.releaseSysDate, a.visitTotal,u.userName ,n.name FROM AcmeMspadminBundle:MspArticle a JOIN a.User u JOIN a.Channel n"; $query = $emt->createQuery($sql." Where a.checkStatus = 0 "); $mspArtile = $query->getResult();
Related recommendations:
Detailed explanation of the usage of Symfony2 controller
Detailed explanation of Symfony2 framework creation project and setting template
Detailed explanation of how Symfony obtains request parameters in templates and behaviors
The above is the detailed content of Detailed explanation of the method of implementing joint query in Symfony2. For more information, please follow other related articles on the PHP Chinese website!