本文整理汇总了PHP中Something::saveAssociated方法的典型用法代码示例。如果您正苦于以下问题:PHP Something::saveAssociated方法的具体用法?PHP Something::saveAssociated怎么用?PHP Something::saveAssociated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Something
的用法示例。
在下文中一共展示了Something::saveAssociated方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSaveAssociatedHabtmWithExtraJoinTableFields
/**
* Test SaveAssociated with Habtm relations and extra join table fields
*
* @return void
*/
public function testSaveAssociatedHabtmWithExtraJoinTableFields()
{
$this->loadFixtures('Something', 'SomethingElse', 'JoinThing');
$data = array('Something' => array('id' => 4, 'title' => 'Extra Fields', 'body' => 'Extra Fields Body', 'published' => '1'), 'SomethingElse' => array(array('something_else_id' => 1, 'doomed' => '1'), array('something_else_id' => 2, 'doomed' => '0'), array('something_else_id' => 3, 'doomed' => '1')));
$Something = new Something();
$result = $Something->saveAssociated($data);
$this->assertFalse(empty($result));
$result = $Something->read();
$this->assertEquals(3, count($result['SomethingElse']));
$this->assertTrue(Set::matches('/Something[id=4]', $result));
$this->assertTrue(Set::matches('/SomethingElse[id=1]', $result));
$this->assertTrue(Set::matches('/SomethingElse[id=1]/JoinThing[something_else_id=1]', $result));
$this->assertTrue(Set::matches('/SomethingElse[id=1]/JoinThing[doomed=1]', $result));
$this->assertTrue(Set::matches('/SomethingElse[id=2]', $result));
$this->assertTrue(Set::matches('/SomethingElse[id=2]/JoinThing[something_else_id=2]', $result));
$this->assertTrue(Set::matches('/SomethingElse[id=2]/JoinThing[doomed=0]', $result));
$this->assertTrue(Set::matches('/SomethingElse[id=3]', $result));
$this->assertTrue(Set::matches('/SomethingElse[id=3]/JoinThing[something_else_id=3]', $result));
$this->assertTrue(Set::matches('/SomethingElse[id=3]/JoinThing[doomed=1]', $result));
}