In a CUniqueValidator rule, I am trying to include some additional attributes in the message. That is, I’d like to do something like this for a rule:
array(
'fooId',
'unique',
'criteria'=>array(
'condition'=>'barId='.$this->barId,
),
'message'=>$this->getRelated('foo')->fullName.' already taken',
),
However, this gives me a "Trying to get property of non-object" error.
Experimenting, I found that this works:
'message'=>Foo::model()->findByPk(47)->fullName.' already taken',
as does this:
'message'=>$this->fooId.' already taken',
but not this:
'message'=>Foo::model()->findByPk($this->fooId)->fullName.' already taken',
I’m stumped. In the last case, $this->fooId ends up as NULL in the findByPk query.