Home > Backend Development > PHP Tutorial > Detailed explanation of the method of implementing joint query in Symfony2

Detailed explanation of the method of implementing joint query in Symfony2

*文
Release: 2023-03-19 10:38:01
Original
1667 people have browsed it

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
Copy after login
Acme\MspadminBundle\Entity\MspChannel:
 type: entity
 table: msp_channel
 oneToMany:
   Articles:
    targetEntity: MspArticle
    mappedBy: Channel
Copy after login
Acme\MspadminBundle\Entity\MspUser:
 type: entity
 table: msp_user
 oneToMany:
   Userone:
    targetEntity: MspArticle
    mappedBy: User
Copy after login

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();
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template