model-unique-validation Allows for easy model validation against all columns while excluding those which are passed in via array

  1. Summary
  2. Typical use case:
  3. Requirements
  4. Links

Summary

Often it is very helpful to test uniqueness of a record/model in the database, but excluding a few columns for one reason or another. Typical cases might be a record which could be entered by more than one individual where there is a database column for that user, userID, and also a datetime field, createdDate, and a primary key, id, all of which are unique. When testing for duplicates it is only going to be valid if these fields are excluded.

It is possible yii already has this functionality now--if this is the case please notify me and I will remove this extension

Typical use case:

// do some work here
$model->attributes = $_POST['SomeClass'];

// exclude some columns which cause issues, or are always unique
$excludeColumns = ['id', 'createdDate', 'userID'];

if( $model->getExists($excludeColumns) )
     $model->addError('id',"This record is not unique.");
else
     $model->save();

Requirements

  • this class, ActiveRecord, to be placed into somewhere meaningful (protected/components/, for example)
  • any models for which this functionality is desired should extend this class.

Links

Project Page

0 0
2 followers
256 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Validation
Developed by: cottonaf
Created on: May 21, 2015
Last updated: 8 years ago

Downloads

show all

Related Extensions