2009-10-06 27 views
2

我有一个有很多IPN的订单表。但是,我没有使用cakephp约定,因为IPN表来自Paypal。我想将订单表的order_num字段加入到IPN表的自定义字段中。所以它会是这样的: select * from orders left join ipn on orders.order_num = ipn.customcakephp一对多的自定义关系连接

如何在models/order.php中正确设置模型关系。

回答

3

我相信这应该做的伎俩,假设我正确理解关系。

class Order extends AppModel { 
    var $primaryKey = 'order_num'; 

    var $hasMany = array(
     'Ipn' => array(
      'className' => 'Ipn', 
      'foreignKey' => 'custom', 
     ), 
    ); 
} 

class Ipn extends AppModel { 
    var $belongsTo = array(
     'Order' => array(
      'className' => 'Order', 
      'foreignKey' => 'custom', 
     ), 
    ); 
} 
+0

我想这和它的作品,但我有两个关系 - 订单的hasMany Orderproduct,订单的hasMany IPN。在Orderproduct关系中,它是Orderproduct.order_id = Order.id。尽管IPN有效,但设置var $ primaryKey使得Orderproduct停止工作。 – jimiyash 2009-10-07 05:04:36

+1

也许你可以在Ipn的beforeFind()中设置$ primaryKey的值呢?例如:function beforeFind(){$ this-> Order-> primaryKey ='order_num'; } function afterFind(){$ this-> Order-> primaryKey ='id'; } – 2009-10-08 20:42:11