/** * testSaveAssociatedHasMany method * * @return void */ public function testSaveAssociatedHasMany() { $this->loadFixtures('Boat', 'Comment'); $TestModel = new Boat(); $TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array(); $result = $TestModel->saveAssociated(array('Boat' => array('id' => 2), 'Comment' => array(array('comment' => 'First new comment', 'published' => 'Y', 'user_id' => 1), array('comment' => 'Second new comment', 'published' => 'Y', 'user_id' => 2)))); $this->assertFalse(empty($result)); $result = $TestModel->findById(2); $expected = array('First Comment for Second Boat', 'Second Comment for Second Boat', 'First new comment', 'Second new comment'); $this->assertEquals($expected, Hash::extract($result['Comment'], '{n}.comment')); $result = $TestModel->saveAssociated(array('Boat' => array('id' => 2), 'Comment' => array(array('comment' => 'Third new comment', 'published' => 'Y', 'user_id' => 1))), array('atomic' => false)); $this->assertFalse(empty($result)); $result = $TestModel->findById(2); $expected = array('First Comment for Second Boat', 'Second Comment for Second Boat', 'First new comment', 'Second new comment', 'Third new comment'); $this->assertEquals($expected, Hash::extract($result['Comment'], '{n}.comment')); $TestModel->beforeSaveReturn = false; $result = $TestModel->saveAssociated(array('Boat' => array('id' => 2), 'Comment' => array(array('comment' => 'Fourth new comment', 'published' => 'Y', 'user_id' => 1))), array('atomic' => false)); $this->assertEquals(array('Boat' => false), $result); $result = $TestModel->findById(2); $expected = array('First Comment for Second Boat', 'Second Comment for Second Boat', 'First new comment', 'Second new comment', 'Third new comment'); $this->assertEquals($expected, Hash::extract($result['Comment'], '{n}.comment')); }