当前位置: 首页>>代码示例>>PHP>>正文


PHP JoinA::read方法代码示例

本文整理汇总了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'));
 }
开发者ID:manzapanza,项目名称:cakephp-api-utils,代码行数:101,代码来源:ModelWriteTest.php


注:本文中的JoinA::read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。