Hello,
Just came across a case where hasMany/belongsTo relations requires
more than one foreign keys from the same model.
Take a wish list for instance. There's two models, User and Wish. A
user can have multiple wishes for him self for sure. And he/she can
pick up others' wishes and claim a exclusive right to help fullful
them. Vice versa on Wish model's part.
In 'wishes' table in DB, there's two foreign keys: 'user_id'
indicating the owner of a wish, and 'claim_by' indicating the kind-
hearted claimer.
Looked into some documents and make the following code, which doesn't
work.
Looking for help here :)
BTW, do you think HABTM is a better solution in such a case like this?
<?php
class user extends AppModel{
var $name = 'User';
var $hasMany = array(
'Wish' => array(
'className' => 'Wish',
'foreignKey' => 'user_id'),
'ClaimedItem' => array(
'className' => 'Wish',
'foreignKey' => 'claim_by'
),
);
}
?>
<?php
class wish extends AppModel{
var $name = 'Wish';
var $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id'),
'Claimer' => array(
'className' => 'User',
'foreignKey' => 'claim_by'
)
);
}
?>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---