Hey,
So I need to check if a user is trying to add a friend who he has already added.
It seems obvious to use the Unique validator, but this causes issues.
My problem is, I need to supply the validator with criteria stating that ‘uid’ must equal the model’s currently set uid attribute.
E.g.
SELECT id FROM friends WHERE friend = value AND uid = theuid
But when I try set the criteria to use $this->uid, it is null.
Although after validation it is not null and is correctly set.
How does the rules() method get called? Because clearly it isn’t allowing me to access attributes.
How else can I do this without writing my own method.
array('friend', 'unique', 'className' => 'Friends', 'attributeName' => 'friend', 'criteria' => array(
'condition' => 'uid = :uid',
'params' => array(':uid' => $this->uid) // $this->uid is null here
)),