Skip to content

Instantly share code, notes, and snippets.

@palibaya
Last active December 16, 2015 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palibaya/5362798 to your computer and use it in GitHub Desktop.
Save palibaya/5362798 to your computer and use it in GitHub Desktop.
Composite Unique
<?php
class MyModel extends CActiveRecord
{
public function rules()
{
return array(
array('attr_a', 'compositeUnique', 'other' => 'attr_b'),
);
}
public function compositeUnique($attribute,$params)
{
$object = $this->model()->findByAttributes(array(
$attribute => $this->{$attribute},
$params['other'] => $this->{$params['other']},
));
if ($object !== null) {
$this->addError($attribute, 'Ur bla..bla.. is not unique!');
}
}
}
@AIMAGU
Copy link

AIMAGU commented Apr 11, 2013

wah mantep sekale gan... Suksesssss...hehe
Thanks bgt gan

@palibaya
Copy link
Author

Hahaha.. padahal belum di ujicoba

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment