How do I test this part?

If it exists
AND the ID is not the current model ID then return false.

How do I test if it's the current model ID?
I have....

if($this->id != ???)
{
   return false;
}

Thanks,

Lance

On Sep 10, 12:56 pm, Lance <[email protected]> wrote:
> Thanks for all the good advice.  I'm a newbie and could use a little
> more specific help if you have an extra minute.
> So if I created a method in the User model like.  I obviously am not
> very good at programming.  Can you guide me in a better direction.
> Sorry for taking more of your time.
>
> Lance
>
> var $validate = array(
> 'rule' => array('checkUnique', 'username'),
>                         'on' => 'update'
> );
>
> function checkUnique()
>         {
>                 if($this->find('all', array('conditions' => 
> array('User.username' =>
> $this->data['User']['username'], array('User.id' => $this->data['User']
> ['id']))))  )
>                 {
>                         $this->invalidate('username_unique');
>                         return false;
>                 }
>                 return true;
>         }
>
> On Sep 10, 12:23 pm, cricket <[email protected]> wrote:
>
> > On Fri, Sep 10, 2010 at 3:21 PM, cricket <[email protected]> wrote:
> > > On Fri, Sep 10, 2010 at 3:06 PM, Lance <[email protected]> wrote:
> > >> I actually want to check isUnique if they edit their username or email
> > >> address.
> > >> I want it to check their changed username or email against the
> > >> database to make sure it already doesn't exist.
> > >> Sorry for the confusion.  Thanks again!
>
> > > My fault, I didn't read that carefully.
>
> > > In this case, you could create a validation method that fetches both
> > > the ID and the value of whichever column you're checking. If it exists
> > > AND the ID is not the current model ID then return false.
>
> > > During validation, you can check $this->id for the current model's ID.
>
> > Sorry, I meant to add that you can keep the built-in isUnique with
> > 'on' => 'create' and then add your second, custom rule with 'on' =>
> > 'update'.
>
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to