2011-04-18 176 views
0

我目前正在建立一个日历,它显示每个事件属于一个事件位置与event_location_id每个eventlocation hasmany事件与外国id event_location_id的外键。根据其id获取event_location的名称。现在即时添加配额交易,我只能得到event_location_id,而不是任何人都可以帮助的名字?或者可能更好地解释什么是外国人的身份和做什么。帮助cakephp外键

我只需要知道如何通过它的id获取事件,然后从事件中获取event_location_id,然后根据event_location_id从event_locations表中获取名称。

+0

如果你可以使用一些标点符号并显示你的代码,那么我们可以帮助你更好 – deceze 2011-04-18 23:51:36

回答

0

如果你有set up your associations properly它应该是那么容易,因为:

$this->Event->recursive = 2; 
$event = $this->Event->read(null, $id); 

debug($event); 

蛋糕自动关联模型获取数据。

+0

递归是做什么的? – 2011-04-19 00:13:40

+0

@josh它告诉Cake要获取多少层关联,实际上你可能甚至不需要它。我建议你学习手册:http://book.cakephp.org/view/1063/recursive – deceze 2011-04-19 00:15:26

1

我会建议使用containable behaviour。它会为你管理递归。对于大多数目的来说,可容纳性将足够好,除非查询非常复杂。