本文整理汇总了PHP中Batch::writeManyMany方法的典型用法代码示例。如果您正苦于以下问题:PHP Batch::writeManyMany方法的具体用法?PHP Batch::writeManyMany怎么用?PHP Batch::writeManyMany使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Batch
的用法示例。
在下文中一共展示了Batch::writeManyMany方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testWriteManyMany_CreateParentAndChildren_WritesManyMany
/**
*
*/
public function testWriteManyMany_CreateParentAndChildren_WritesManyMany()
{
$parent = new Batman();
$parent->Name = 'Bruce Wayne';
$parent->Car = 'Bat mobile';
$children = array();
for ($i = 0; $i < 5; $i++) {
$child = new Child();
$child->Name = 'Soldier #' . $i;
$children[] = $child;
}
$batch = new \Batch();
$batch->write(array($parent));
$batch->write($children);
$sets = array();
foreach ($children as $child) {
$sets[] = array($parent, 'Children', $child);
}
$batch->writeManyMany($sets);
$parent = Human::get()->first();
$this->assertEquals(5, $parent->Children()->Count());
}
示例2: testOnAfterExists_ArrayCondition_CalledBack
/**
*
*/
public function testOnAfterExists_ArrayCondition_CalledBack()
{
$parent = new Human();
$parent->Name = 'Bob';
$children = array();
for ($i = 0; $i < 5; $i++) {
$child = new Child();
$child->Name = 'Soldier #' . $i;
$children[] = $child;
}
$batch = new \Batch();
$afterExists = new \OnAfterExists(function () use($batch, $parent, $children) {
$sets = array();
foreach ($children as $child) {
$sets[] = array($parent, 'Children', $child);
}
$batch->writeManyMany($sets);
});
$afterExists->addCondition($parent);
$afterExists->addCondition($children);
$batch->write(array($parent));
$batch->write($children);
$parent = Human::get()->first();
$this->assertEquals(5, $parent->Children()->Count());
}