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:

Book

  public $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+unsubscr...@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.

Reply via email to