equals() public method

The comparison is made by comparing the table names and the primary key values of the two active records. If one of the records [[isNewRecord|is new]] they are also considered not equal.
public equals ( ActiveRecord $record ) : boolean
$record ActiveRecord record to compare to
return boolean whether the two active records refer to the same row in the same database table.
Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function equals($record)
 {
     if ($this->isNewRecord && $record->isNewRecord) {
         return $record === $this;
     }
     return parent::equals($record);
 }
Exemplo n.º 2
0
 /**
  * Проверяет наличие AR $object в массиве $object
  * если любой из аргументов пуст позвращается false
  * @param ActiveRecord $object
  * @param ActiveRecord[] $array
  * @return bool
  */
 public static function activeRecordInArray(ActiveRecord $object, $array)
 {
     if (empty($object) || empty($array)) {
         return false;
     }
     foreach ($array as $element) {
         if ($object->equals($element)) {
             return true;
         }
     }
     return false;
 }