unique-multiple-columns-validate

Validates that a combination of attribute values is unique in the corresponding database table
10 followers

This extension, takes a combination of Model attributes and verifies uniqueness of the combination in the database table.

Credit: I took the original code posted by me23 at this Forum topic and packaged it with minor modification to raise an error referencing the attribute combination and not a single attribute. Other than that, the credit it to the community.

Documentation

Requirements

  • Yii 1.0 or above

Installation

  • Extract the release file under protected/extensions

Usage

See the following code example:

public function rules()
{
    return array(
        ....
        array('attribute1+attribute2+attribute3', 'application.extensions.uniqueMultiColumnValidator'),
        ....

Change Log

October 23, 2009

Total 9 comments

#6865 report it
jmariani at 2012/02/09 02:52pm
Make it work with fields of type date

Or, you can pass the parameter when configuring the rule.

#6863 report it
lvaghi at 2012/02/09 01:40pm
Make it work with fields of type date

Make it work with name and date combination

The extension does not work when a field is a date. This is due to the conversion to lowercase which is performed when the caseSensitive property is left to false, which is the default. My brutal fix was to change the default from false to true in row 8 of the class uniqueMultiColumnValidator.php

Hope someone will provide a better fix (testing for field type before the conv. to lowercase, etc...)

#6674 report it
jmariani at 2012/01/27 12:01pm
Thumbs up!

Thank you!

#5957 report it
adinugro at 2011/11/29 06:03pm
Excellent ext, but not working with name and date combination

Hi,

I have Member table which contains membershipNo, name and date, I want to implement a validation that combination of name and date must be unique, but the validation always through....... If I changed to membershipNo and name it works fine.

Any hints?

#2481 report it
Bibi40k at 2011/01/08 07:46am
another bug :(

Hi, what should i do to make it check the values after the beforeSave() makes changes ?

#2456 report it
szako at 2011/01/05 06:45am
Thanks

Thank you, i didn't have to reinvert the wheel. :) Works like a charm.

@Inkvizitor: What' with NULL values?

#437 report it
tydeas_dr at 2010/06/02 08:09am
Great for my purpose

Firstly great job, congrat to me23 afiouni and community. @Inkvizitor: What's the behavior of null values ?

#904 report it
Inkvizitor at 2010/02/07 06:03am
Good job.

One problem: extension doesn't work with NULL values correctly.

#1161 report it
jerry2801 at 2009/11/20 08:57am
great!

Thanks for share!

Leave a comment

Please to leave your comment.

Create extension
  • License: Other Open Source License
  • Developed by: afiouni
  • Category: Validation
  • Votes: +8
  • Downloaded: 990 times
  • Created on: Oct 23, 2009
  • Last updated: Oct 23, 2009