Php 从JOIN访问与条令相关的字段
我正试图从我的数据库中提取一个使用条令的用户列表,并加入一个连接。我的模型中有以下功能:Php 从JOIN访问与条令相关的字段,php,symfony1,doctrine,Php,Symfony1,Doctrine,我正试图从我的数据库中提取一个使用条令的用户列表,并加入一个连接。我的模型中有以下功能: public function getAttendees() { $q = Doctrine_Query::create() ->select('a.id, a.name, a.url, m.id') ->from('Attendees a') ->leftJoin('a.Meetings m WITH m.Meeting_Slot_
public function getAttendees() {
$q = Doctrine_Query::create()
->select('a.id, a.name, a.url, m.id')
->from('Attendees a')
->leftJoin('a.Meetings m WITH m.Meeting_Slot_ID = ?', $this->getId());
return $q->execute();
}
我已经检查了这个查询生成的SQL,它正在处理我想要的所有数据。我现在正在尝试访问检索到的数据。我有以下工作:
foreach($object0>getAttendees() as $attendee){
echo $attendee->getName();
}
但是,我不知道如何访问m.id字段。我认为您可以这样做:
$attendee->getMeetings()->getId()
必须使用schema.yml中定义的别名(如果使用的是symfony)
通常,条令使用这种方式将相关模型链接在一起:
模型1->模型2->模型3
…->getModel2()->getModel3()->getModel3Field()
$attendee->getMeeting()->getId()根据您对关系/属性的命名方式,代码>或soemthing会产生这种效果。实际上,getMeetings()会返回一个会议数组,因为这是一个一对多关系。