का उपयोग करके कई से अधिक रिश्ते पर आंतरिक कैसे काम करता है मैंने हाल ही में ManyToMany
संबंधों में शामिल होने के साथ एक समस्या का समाधान किया, समाधान इस answer के समान था और यह सोच रहा था कि यह कैसे काम करता है। मान लीजिए कि मैं groups
और team
के बीच एक सरल ManyToMany
संबंध है, वहाँ एक groups_team
टेबल कि स्वचालित रूप से क्रम में यहांडॉक्टरेट और सिम्फनी 2
समूहों इकाई
/**
* Groups
*
* @ORM\Table(name="groups")
* @ORM\Entity(repositoryClass="AppBundle\Model\Repository\GroupsRepository")
*/
class Groups {
/**
* @ORM\ManyToMany(targetEntity="Team", inversedBy="group")
*/
protected $team;
public function __construct() {
$this->team = new ArrayCollection();
}
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="groupname", type="string", length=255)
*/
private $groupname;
//obligatory getters and setters :)
टीम इकाई
/**
* Team
*
* @ORM\Table(name="team")
* @ORM\Entity(repositoryClass="AppBundle\Model\Repository\TeamRepository")
*/
class Team {
/**
* @ORM\ManyToMany(targetEntity="Groups", mappedBy="team")
*/
protected $group;
public function __construct(){
$this->group = new ArrayCollection();
}
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="teamname", type="string", length=255)
*/
private $team;
//[setters and getters here]
बनाया जाएगा होगा एक समूह में सभी टीमों को प्राप्त करने के लिए मुझे groups_team
table.I से पूछताछ करनी होगी। मैंने केवल mysql में तालिका की पूछताछ की होगी लेकिन अंदर सिम्फोनी मैं कैसे innerJoin
काम कर रहा है इस
$groups = $em->getRepository("AppBundle\Model\Entity\Groups")->findBy(array('tournament' => $tournament->getId()));
//get all teams with group id in groups_team table
foreach ($groups as $group) {
$teamsingroup = $em->getRepository("AppBundle\Model\Entity\Team")->createQueryBuilder('o')
->innerJoin('o.group', 't')
->where('t.id = :group_id')
->setParameter('group_id', $group->getId())
->getQuery()->getResult();
echo "</b>".$group->getGroupname()."</b></br>";
foreach ($teamsingroup as $teamingroup) {
echo $teamingroup->getTeam()."</br>";
}
}
किसी ने मुझे बता सकते हैं क्या करना है और इस के पीछे की अवधारणा, इस बारे में जानने के शायद कुछ प्रलेखन क्या है। सिम्फनी और सिद्धांत के साथ ऐसा करने का बेहतर तरीका है।
धन्यवाद, यह मेरा कोड कम कर दिया, और यह मुझे अधिक सुव्यवस्थित कोड सोचने के लिए मेरे रास्ते पर शुरू किया। इसने मेरे प्रश्न का उत्तर 100% दिया। एसओ एक महान मंच है। +1 –