ttgive / qeephp

Automatically exported from code.google.com/p/qeephp
0 stars 0 forks source link

ActiveRecord 的“脏对象” #74

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
对于一个 ActiveRercord 
对象,如果从数据库中查询出来后修改了属性,那么该对象
将被置为“脏对象”。

$article = Article::find(...);
echo $article->changed(); // false

// Track changes to individual attributes
$article->title = "New Title";
echo $article->changed('title'); // true

// Get the hash of changed attributes and their previous and current values
echo $article->changes(); // array('title')

不带参数的 changed() 
方法指示对象是否是一个“脏对象”。而指定了参数的
changed() 方法,则指示特定属性是否发生了改变。

changes() 方法返回所有改变了的属性名。

Original issue reported on code.google.com by dualf...@gmail.com on 27 May 2008 at 2:48

GoogleCodeExporter commented 9 years ago

Original comment by dualf...@gmail.com on 27 May 2008 at 2:49

GoogleCodeExporter commented 9 years ago
调用 save() 
方法时,如果对象不是“脏对象”,则不会更新该对象在数��
�库中的记录。但是这不
会影响关联对象的保存。同时,save() 
方法还会消除“脏对象”状态。

如果没有通过 $obj->prop 的方式更新属性,需要调用 
willChanged() 方法来指示哪些属性已经
做了修改,并将设置“脏对象”状态。

Original comment by dualf...@gmail.com on 27 May 2008 at 2:54

GoogleCodeExporter commented 9 years ago
completed

Original comment by dualf...@gmail.com on 7 Jun 2008 at 2:30