比较两个Doctrine_Record对象 [英] Compare two Doctrine_Record objects

查看:160
本文介绍了比较两个Doctrine_Record对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何比较两个 Doctrine_Record 对象,看看它们是否相等?

How do I compare two Doctrine_Record objects to see if they are "equal"?

login我正在考虑,如果它们具有相同的属性值,两个对象是相等的,除了 id created_at updated_at 字段(a la Timestampable )。

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

这篇关于比较两个Doctrine_Record对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆