public function test_n_m_n() { $this->installAndIncludeModels(array('User', 'Post', 'Comment')); $this->User = new User(); if ($this->User->_db->type() == 'postgre') { // from postgres docs: // // A value of type name is a string of 63 or fewer characters. // A name must start with a letter or an underscore; // the rest of the string can contain letters, digits, and underscores. // IF a column name here is over 63 characters long, the assoc finder will fail $this->assertTrue(true); return; } $User1 = new User(array('name' => 'Arno', 'email' => '*****@*****.**')); $User2 = new User(array('name' => 'Arno', 'email' => '*****@*****.**')); $Post1 = new Post(array('title' => 'Test1')); $Post2 = new Post(array('title' => 'Test2')); $Post3 = new Post(array('title' => 'Test3')); $Comment1_1 = new Comment(array('name' => 'Comment1_1')); $Comment1_2 = new Comment(array('name' => 'Comment1_2')); $Comment2_1 = new Comment(array('name' => 'Comment2_1')); $Comment2_2 = new Comment(array('name' => 'Comment2_2')); $Comment3_1 = new Comment(array('name' => 'Comment3_1')); $Comment3_2 = new Comment(array('name' => 'Comment3_2')); $User1->post->add($Post1); $User1->post->add($Post2); $User2->post->add($Post3); $Post1->comment->add($Comment1_1); $Post1->comment->add($Comment1_2); $Post2->comment->add($Comment2_1); $Post2->comment->add($Comment2_2); $Post3->comment->add($Comment3_1); $Post3->comment->add($Comment3_2); $User1->save(); $User2->save(); $Post1->save(); $Post2->save(); $Post3->save(); $Comment1_1->save(); $Comment1_2->save(); $Comment2_1->save(); $Comment2_2->save(); $Comment3_1->save(); $Comment3_2->save(); $Test = $User1->findAllBy('name', 'Arno', array('order' => 'id ASC', 'include' => array('posts' => array('order' => 'id ASC', 'include' => array('comments' => array('order' => 'id ASC')))))); $this->assertEqual($Test[0]->email, '*****@*****.**'); $this->assertEqual($Test[1]->email, '*****@*****.**'); $this->assertEqual($Test[0]->posts[0]->title, 'Test1'); $this->assertEqual($Test[0]->posts[1]->title, 'Test2'); $this->assertEqual($Test[0]->posts[0]->comments[0]->name, 'Comment1_1'); $this->assertEqual($Test[0]->posts[0]->comments[1]->name, 'Comment1_2'); $this->assertEqual($Test[0]->posts[1]->comments[0]->name, 'Comment2_1'); $this->assertEqual($Test[0]->posts[1]->comments[1]->name, 'Comment2_2'); $this->assertEqual($Test[1]->posts[0]->title, 'Test3'); $this->assertEqual($Test[1]->posts[0]->comments[0]->name, 'Comment3_1'); $this->assertEqual($Test[1]->posts[0]->comments[1]->name, 'Comment3_2'); }