|
|
@@ -6606,6 +6606,62 @@ class ModelWriteTest extends BaseModelTest {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * testSaveAllDeepHasManyhasMany method
|
|
|
+ *
|
|
|
+ * return @void
|
|
|
+ */
|
|
|
+ public function testSaveAllDeepHasManyHasMany() {
|
|
|
+ $this->loadFixtures('Article', 'Comment', 'User', 'Attachment');
|
|
|
+ $TestModel = new Article();
|
|
|
+ $TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array();
|
|
|
+ $TestModel->Comment->unbindModel(array('hasOne' => array('Attachment')), false);
|
|
|
+ $TestModel->Comment->bindModel(array('hasMany' => array('Attachment')), false);
|
|
|
+
|
|
|
+ $this->db->truncate($TestModel);
|
|
|
+ $this->db->truncate(new Comment());
|
|
|
+ $this->db->truncate(new Attachment());
|
|
|
+
|
|
|
+ $result = $TestModel->saveAll(array(
|
|
|
+ 'Article' => array('id' => 2, 'title' => 'I will not save'),
|
|
|
+ 'Comment' => array(
|
|
|
+ array('comment' => 'First new comment', 'published' => 'Y', 'user_id' => 1),
|
|
|
+ array(
|
|
|
+ 'comment' => 'hasmany', 'published' => 'Y', 'user_id' => 5,
|
|
|
+ 'Attachment' => array(
|
|
|
+ array('attachment' => 'first deep attachment'),
|
|
|
+ array('attachment' => 'second deep attachment'),
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
+ ), array('deep' => true));
|
|
|
+
|
|
|
+ $result = $TestModel->Comment->find('first', array(
|
|
|
+ 'conditions' => array('Comment.comment' => 'hasmany'),
|
|
|
+ 'fields' => array('id', 'comment', 'published', 'user_id'),
|
|
|
+ 'recursive' => -1
|
|
|
+ ));
|
|
|
+ $expected = array(
|
|
|
+ 'Comment' => array(
|
|
|
+ 'id' => 2,
|
|
|
+ 'comment' => 'hasmany',
|
|
|
+ 'published' => 'Y',
|
|
|
+ 'user_id' => 5
|
|
|
+ )
|
|
|
+ );
|
|
|
+ $this->assertEquals($expected, $result);
|
|
|
+
|
|
|
+ $result = $TestModel->Comment->Attachment->find('all', array(
|
|
|
+ 'fields' => array('attachment', 'comment_id'),
|
|
|
+ 'order' => array('Attachment.id' => 'ASC')
|
|
|
+ ));
|
|
|
+ $expected = array(
|
|
|
+ array('Attachment' => array('attachment' => 'first deep attachment', 'comment_id' => 2)),
|
|
|
+ array('Attachment' => array('attachment' => 'second deep attachment', 'comment_id' => 2)),
|
|
|
+ );
|
|
|
+ $this->assertEquals($expected, $result);
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
* testUpdateAllBoolean
|
|
|
*
|
|
|
* return @void
|