I sorted it out by using the HasMany thorough relation and by correcting the $data feed.
On Friday, February 6, 2015 at 8:46:08 PM UTC, gt0p wrote:
-- On Friday, February 6, 2015 at 8:46:08 PM UTC, gt0p wrote:
I am trying to bind 3 tables and I am having problems with proper relations.Table users (pk id), books (pk id), users_books (user_id, book_id), comments (pk and foreign key book_id, user_id -> with reference to users_books)Here are the models:Bookpublic $hasAndBelongsToMany = array('User' =>array('className' => 'User','joinTable' => 'users_books','foreignKey' => 'book_id','associationForeignKey' => 'user_id','unique' => true,'conditions' => '','fields' => '','order' => '','limit' => '','offset' => '','finderQuery' => '',// 'with' => 'UserBook'),);public $hasMany = array('Comment'=>array('className'=>'Comment')); Comment:public $belongsTo = array ('Book' => array ('className'=>'Book',));When I try to save with the saveAll method I got:Error: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`metabook`.`comments`, CONSTRAINT `comments_ibfk_1` FOREIGN KEY (`user_id`, `book_id`) REFERENCES `users_books` (`user_id`, `book_id`))I know that this is not according to the cakephp conventions, but what I can do to bind those tables?
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment