如何检测加载的ORM对象已更改?
如标题所示:如何检测加载的ORM对象已更改(当前值与db表中的值不同)?ORM保留一个名为“更改”的数组以跟踪列中的更改,您可以这样检查它如何检测加载的ORM对象已更改?,orm,kohana,kohana-3,Orm,Kohana,Kohana 3,如标题所示:如何检测加载的ORM对象已更改(当前值与db表中的值不同)?ORM保留一个名为“更改”的数组以跟踪列中的更改,您可以这样检查它 public function save() { if (isset($this->changed['name'])) { // set the slug when the name changes -- 'my-post-name' $this->slug = url::title($this->n
public function save()
{
if (isset($this->changed['name']))
{
// set the slug when the name changes -- 'my-post-name'
$this->slug = url::title($this->name);
}
}
检查此链接-=>changedORM保留一个名为“changed”的数组来跟踪列中的更改,您可以这样检查它
public function save()
{
if (isset($this->changed['name']))
{
// set the slug when the name changes -- 'my-post-name'
$this->slug = url::title($this->name);
}
}
检查此链接-=>已更改依赖于save()方法使用的更改的问题是set()方法中使用的比较是由!==接线员
因此,有时如果值相同,但一侧为字符串,另一侧为整数,ORM会将其检测为不同。依赖save()方法使用的更改的问题是set()方法中使用的比较由!==接线员
因此,有时如果值相同,但一边是字符串,另一边是整数,ORM会检测到它不同。谢谢,我发现如果您想检查任何更改的字段,您可以使用$this->\u saved;ToUpdate for Kohana 3.x
if($this->changed('name')){…}
谢谢,我发现如果您想检查任何更改的字段,只需使用$this->\u saved;ToUpdate for Kohana 3.xif($this->changed('name')){…}