hi,
i have 2 models in HABTM relation: Users HABTM Books
the trick is that i have an extra column in the users_books table
called relation_type
this is my relation definition from my User model:
var $hasAndBelongsToMany = array(
"UserBookshelf" => array('className' => 'Book',
'joinTable' => 'users_books',
'foreignKey' => 'user_id',
'associationForeignKey' => 'book_id',
'conditions' =>
'UsersBook.relation_type=1',
'order' => '',
'limit' => '',
'uniq' => true,
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
),
"UserWishlist" => array('className' => 'Book',
'joinTable' => 'users_books',
'foreignKey' => 'user_id',
'associationForeignKey' => 'book_id',
'conditions' =>
'UsersBook.relation_type=2',
'order' => '',
'limit' => '',
'uniq' => true,
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
my question is how can i save the id-s with a given relation_type?
this is the code that i've tried in my users_controller:
$this->User->contain(array('UserBookshelf'));
$this->data['UserBookshelf']['UserBookshelf'] = array($bookId);
$this->User->id = $this->Auth->user('id');
$this->User->save($this->data, false);
the conditions from the relation definition
('UsersBook.relation_type=1') only used in select statements, but i
can't specify the relation type in the insert statement.
thanks,
gbk
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---