有谁能解释一下phalcon如何使用结果集?当我走路时抛出结果集并更改一些项目属性,之后我再次走路 - 我的所有更改都丢失了。
我做错了什么?
来自控制器的示例代码:
public function testAction()
{
$content = "<h2>Test update resultset w/o saving data</h2>";
/** @var OrdersItems[] $items */
$items = OrdersItems::find("external_item_id = 'Test'");
$i = 1;
foreach ($items as $item) {
$content .= $item->name . ': supplier_id update from ' . $item->supplier_id . ' to ' . $i++ . "<br />";
$item->supplier_id = $i;
}
$content .= "<hr /><h2>Walk again throw items</h2>";
foreach ($items as $item) {
$content .= $item->name . ': supplier_id = ' . $item->supplier_id . "<br />";
}
return $this->response->setContent($content);
}
结果输出:
Test update resultset w/o saving data
Autogenerated item 1: supplier_id update from 5 to 1
Autogenerated item 2: supplier_id update from 4 to 2
Autogenerated item 3: supplier_id update from 3 to 3
Autogenerated item 4: supplier_id update from 2 to 4
Autogenerated item 5: supplier_id update from 1 to 5
Walk again throw items
Autogenerated item 1: supplier_id = 5
Autogenerated item 2: supplier_id = 4
Autogenerated item 3: supplier_id = 3
Autogenerated item 4: supplier_id = 2
Autogenerated item 5: supplier_id = 1