2012-05-29 40 views

回答

3

第五正常可與 「$的has_many通過」 來表示

http://www.phpactiverecord.org/projects/main/wiki/Associations

has_many through (many to many) 

This is a convenient way to configure a many-to-many association. 

在這個例子中的順序是由去的 與用戶相關聯的付款協會。

1 class Order extends ActiveRecord\Model { 
2 static $has_many = array(
3  array('payments'), 
4  array('users', 'through' => 'payments') 
5 ); 
6 } 
7 
8 class Payment extends ActiveRecord\Model { 
9 static $belongs_to = array(
10  array('user'), 
11  array('order') 
12 ); 
13 } 
14 
15 class User extends ActiveRecord\Model { 
16 static $has_many = array(
17  array('payments') 
18 ); 
19 } 
20 
21 $order = Order::first(); 
22 # direct access to users 
23 print_r($order->users); # will print an array of User object 

我找到了答案在這裏:

您可以創建接合表的模型,然後將電話表通過連接表關聯!

http://www.phpactiverecord.org/boards/4/topics/226

也發現了這個: http://svn.phpontrax.com/wiki/ActiveRecordTableAssociations