Solar_Filter_ValidateUnique::validateUnique()

public bool Solar_Filter_ValidateUnique::validateUnique ( mixed $value , mixed $where = NULL )

Validates that a value for the current data key is unique among all model records of its inheritance type.

Parameters

  • (mixed) $value: The value to validate.

  • (mixed) $where: Additional "WHERE" conditions to exclude records from the uniqueness check.

Returns

  • (bool) True if unique, false if not.

Description

Validates that a value for the current data key is unique among all model records of its inheritance type.

This will exclude any record having the same primary-key value as the current record.

N.b.: If you are attempting to validate the primary column as unique, you have to pass an additional $where condition on another unique column. This is so the record being validated can recognize "itself" in the database. For example ...

<?php
// validate 'foo' as unique when 'foo' is the primary column.
// we need to make sure the record recognizes itself by some
// other unique column value, 'bar'.  this is from inside a
// Solar_Sql_Model::_setup() method.
$where = array("bar != :bar AND bar IS NOT NULL")
$this->_addFilter('foo', 'validateUnique', $where);

... but really, you should be using an artificial key (e.g. integer id autoincremented) as your primary, not a natural key. It makes this so much easier.



Local