我在加入表时遇到了 Codeigniter Datamapper 的问题。我有 2 张桌子:
Purchase
purchase_id, ref ...
Stock
stock_id, purchase_ref...
我创建了一个 has_many 关系:
购买:
public $has_many = array(
'stock' => array(
'join_table' => 'stocks',
'other_field' => 'purchase_ref',
'cascade_delete' => TRUE
)
);
对于库存:
public $has_one = array(
'purchase'=>array(
'join_other_as' => 'purchase_ref',
'join_table' => 'purchases',
'cascade_delete' => FALSE
)
);
但是datamapper似乎将_id附加到我想加入的列中,它是purchase_ref_id,sql语句变成了这样:
...LEFT OUTER JOIN "stocks" stocks ON "purchases"."id" = "stocks"."purchase_ref_id"...
无论如何,在datamapper中加入表时避免附加_id?多谢。