My table have the following informations: company, year and number. All them are part of a unique key.
I know how to validate a basic unique key, but how can I make rules() to validate my key?
Thx!
Page 1 of 1
How to validate composite unique key?
#2
Posted 15 June 2009 - 09:45 AM
You can change the return value of the rules method of your model.
More information you can find in the documentation: http://www.yiiframew...uide/form.model
public function rules()
{
return array(
array('attriubteThatNeedsToBeUnique', 'myValidator'),
);
}
public function myValidator($attribute,$params)
{
//do your check here
}
More information you can find in the documentation: http://www.yiiframew...uide/form.model
#3
Posted 15 June 2009 - 12:26 PM
In Yii, we have
I am thinking that Yii have somehing like
But this don't work.
public function rules()
{
return array(
array('myAttribute', 'unique'),
);
}
I am thinking that Yii have somehing like
public function rules()
{
return array(
array(array('attr1', 'attr2', 'attr3'), 'unique'),
);
}
But this don't work.
#4
Posted 15 June 2009 - 01:44 PM
The uniqueness check for composite key is not supported currently. We may consider implementing it in 1.1. Could you please create a ticket for this? Right now, you will need to implement it by yourself using either a method-based or class-based validation.
Share this topic:
Page 1 of 1

Help
This topic is locked












