Reputation: 330
Hy,
I have 2 tables:
-1. users- (id, name, surname, mail.....)
-2. orders- (id, date, owner, aprowed_by.....)
And problem is: fields owner and aprowed_by need to be foreign keys from table users and named users_id but i cant name both fields users_id. I linked relations in php my admin, and baked CRUD code, but ofcourse it want work. I tried next from google and from cake site:
Multiple relations to the same model- http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html
HABTM- http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html
But it want work. maybe i work something wrong, but if someone could see what kind of relations would be that or give me some tip?
Thanks in advance, Best regards
Upvotes: 1
Views: 404
Reputation: 5271
Using the Multiple relations to the same model knowledge, your models should have code like this:
User
public $hasMany = array(
'Owned_Order' => array(
'className' => 'Order',
'foreignKey' => 'owner'),
'Aprowed_Order' => array(
'className' => 'Order',
'foreignKey' => 'aprowed_by')
);
Order
public $belongsTo = array(
'Owner' => array(
'className' => 'User',
'foreignKey' => 'owner'),
'Aprowed' => array(
'className' => 'User',
'foreignKey' => 'aprowed_by')
);
Upvotes: 3