本文整理汇总了PHP中JoinA::read方法的典型用法代码示例。如果您正苦于以下问题:PHP JoinA::read方法的具体用法?PHP JoinA::read怎么用?PHP JoinA::read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JoinA
的用法示例。
在下文中一共展示了JoinA::read方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSaveHabtm
//.........这里部分代码省略.........
$this->assertEquals($data['Tag'], $result['Tag']);
$TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment')));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body'), 'Tag' => array(array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31')));
$this->assertEquals($expected, $result);
$data = array('Article' => array('id' => '2'), 'Tag' => array('Tag' => array(2, 3)));
$result = $TestModel->set($data);
$this->assertFalse(empty($result));
$result = $TestModel->save();
$this->assertFalse(empty($result));
$TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment')));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body'), 'Tag' => array(array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'), array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31')));
$this->assertEquals($expected, $result);
$data = array('Tag' => array('Tag' => array(1, 2, 3)));
$result = $TestModel->set($data);
$this->assertFalse(empty($result));
$result = $TestModel->save();
$this->assertFalse(empty($result));
$TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment')));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body'), 'Tag' => array(array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'), array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31')));
$this->assertEquals($expected, $result);
$data = array('Tag' => array('Tag' => array()));
$result = $TestModel->set($data);
$this->assertFalse(empty($result));
$result = $TestModel->save();
$this->assertFalse(empty($result));
$data = array('Tag' => array('Tag' => ''));
$result = $TestModel->set($data);
$this->assertFalse(empty($result));
$result = $TestModel->save();
$this->assertFalse(empty($result));
$TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment')));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body'), 'Tag' => array());
$this->assertEquals($expected, $result);
$data = array('Tag' => array('Tag' => array(2, 3)));
$result = $TestModel->set($data);
$this->assertFalse(empty($result));
$result = $TestModel->save();
$this->assertFalse(empty($result));
$TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment')));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body'), 'Tag' => array(array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'), array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31')));
$this->assertEquals($expected, $result);
$data = array('Tag' => array('Tag' => array(1, 2)), 'Article' => array('id' => '2', 'title' => 'New Second Article'));
$result = $TestModel->set($data);
$this->assertFalse(empty($result));
$result = $TestModel->save();
$this->assertFalse(empty($result));
$TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment')));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body'), 'Tag' => array(array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31')));
$this->assertEquals($expected, $result);
$data = array('Tag' => array('Tag' => array(1, 2)), 'Article' => array('id' => '2', 'title' => 'New Second Article Title'));
$result = $TestModel->set($data);
$this->assertFalse(empty($result));
$result = $TestModel->save();
$this->assertFalse(empty($result));
$TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment')));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'New Second Article Title', 'body' => 'Second Article Body'), 'Tag' => array(array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31')));
$this->assertEquals($expected, $result);
$data = array('Tag' => array('Tag' => array(2, 3)), 'Article' => array('id' => '2', 'title' => 'Changed Second Article'));
$result = $TestModel->set($data);
$this->assertFalse(empty($result));
$result = $TestModel->save();
$this->assertFalse(empty($result));
$TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment')));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Changed Second Article', 'body' => 'Second Article Body'), 'Tag' => array(array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'), array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31')));
$this->assertEquals($expected, $result);
$data = array('Tag' => array('Tag' => array(1, 3)), 'Article' => array('id' => '2'));
$result = $TestModel->set($data);
$this->assertFalse(empty($result));
$result = $TestModel->save();
$this->assertFalse(empty($result));
$TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment')));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Changed Second Article', 'body' => 'Second Article Body'), 'Tag' => array(array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31')));
$this->assertEquals($expected, $result);
$data = array('Article' => array('id' => 10, 'user_id' => '2', 'title' => 'New Article With Tags and fieldList', 'body' => 'New Article Body with Tags and fieldList', 'created' => '2007-03-18 14:55:23', 'updated' => '2007-03-18 14:57:31'), 'Tag' => array('Tag' => array(1, 2, 3)));
$result = $TestModel->create() && $TestModel->save($data, true, array('user_id', 'title', 'published'));
$this->assertFalse(empty($result));
$TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment')));
$result = $TestModel->read();
$expected = array('Article' => array('id' => 4, 'user_id' => 2, 'title' => 'New Article With Tags and fieldList', 'body' => '', 'published' => 'N', 'created' => '', 'updated' => ''), 'Tag' => array(0 => array('id' => 1, 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), 1 => array('id' => 2, 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'), 2 => array('id' => 3, 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31')));
$this->assertEquals($expected, $result);
$this->loadFixtures('JoinA', 'JoinC', 'JoinAC', 'JoinB', 'JoinAB');
$TestModel = new JoinA();
$TestModel->hasBelongsToMany = array('JoinC' => array('unique' => true));
$data = array('JoinA' => array('id' => 1, 'name' => 'Join A 1', 'body' => 'Join A 1 Body'), 'JoinC' => array('JoinC' => array(array('join_c_id' => 2, 'other' => 'new record'), array('join_c_id' => 3, 'other' => 'new record'))));
$TestModel->save($data);
$result = $TestModel->read(null, 1);
$expected = array(4, 5);
$this->assertEquals($expected, Hash::extract($result, 'JoinC.{n}.JoinAsJoinC.id'));
$expected = array('new record', 'new record');
$this->assertEquals($expected, Hash::extract($result, 'JoinC.{n}.JoinAsJoinC.other'));
}