Compare two Doctrine_Record objects
How do I compare two Doctrine_Record
objects to see if they are "equal"?
On the domain login I am considering, t开发者_运维知识库wo objects are equal if they have the same properties values, except the id
and the created_at
and updated_at
fields (a la Timestampable
).
First idea which comes into my mind is:
class User extends Doctrine_Record
{
public function equals(User $user)
{
$left = $this->toArray();
$right = $user->toArray();
unset($left['id'], $left['created_at'], $left['updated_at']);
unset($right['id'], $right['created_at'], $right['updated_at']);
return $left == $right;
}
}
精彩评论