Skip to content

Instantly share code, notes, and snippets.

@palibaya

palibaya/gist:5362798

Last active Dec 16, 2015
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@AIMAGU AIMAGU commented Apr 11, 2013

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

@palibaya

This comment has been minimized.

Copy link
Owner Author

@palibaya palibaya commented Apr 11, 2013

Hahaha.. padahal belum di ujicoba

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