1

是否可以在 PHP ActiveRecord 中表示第五范式?

IE

Person <=> (person_id) person_phone (phone_id) <=> Phone
4

1 回答 1

3

第五个法线可以用“$has_many through”表示

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

于 2012-05-29T16:30:06.717 回答