Validation rule message

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.

I should add that this is being used to create multiple new records at once, and that I am using Form Builder. So the issue probably lies somewhere in the function I am using to loop over the $_POST array data, validating each new model.