views:

21

answers:

1

Hi!

What would to know the best way to compare two objects using Doctrine! On the domain login I am considering, two objects are equal if they have the same properties values, except the id and the created_at and updated_at auto-generated fields through the Timestampable behavior.

Thanks in advance for the help, Best regards!

A: 

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;
  }
}
kuba