He Brendon, I always forget that 'on' thing ;) I tried: 'Duplicate' => array( 'rule' => array('isUnique'), 'on' => 'create', 'message' => 'This nick is already taken. Choose another or sign in' )
But still is given me this validation message when I try to do $this- >items->saveAll($this->data, array('validate'=>'first'))); Maybe the saveAll thinks that it is always a create. It does do a SELECT on the authors table, but still comes back with the 'Duplicate' validation error message. Do I something wrong? On Aug 15, 10:33 pm, BrendonKoz <[EMAIL PROTECTED]> wrote: > In your rule that you set "isUnique", just make it so that the "on" > key within that rule is set to "create" for the nickname field. > Problem solved. > > On Aug 15, 3:58 am, Primeminister <[EMAIL PROTECTED]> wrote: > > > He Teknoid, thnx for your reply! > > This works great, but I want an update if the nickname already exists > > and an insert if not. > > I thought in beforeSave() getting the ID of that nickname would be > > sufficient. > > > Is there another way to do this with saveAll()? Or do I just have to > > do save() twice (Items and Author)? > > > On Aug 14, 6:31 pm, teknoid <[EMAIL PROTECTED]> wrote: > > > > saveAll() will validate both of your models, and only save if both > > > models pass validation. > > > (Ensure that your DB supports transactions and use 'validate'=>'first' > > > for options). > > > This way you don't need any beforeSave() trickery, and you can rely on > > > something like 'isUnique' > > > > saveAll() handles the rest... > > > > On Aug 14, 10:14 am, Primeminister <[EMAIL PROTECTED]> wrote: > > > > > Hi! > > > > > I use save all on Items which is associated with Authors (Item > > > > belongsTo Author) and I have a beforeSave() in model Author which > > > > checks if the nickname already exists and add the Author id to > > > > this->data when it does exists. > > > > > When I do $this->Item->saveAll() I print the $this->data in > > > > Author.beforeSave() > > > > Array > > > > ( > > > > [Author] => Array > > > > ( > > > > [nick] => primeminister > > > > [modified] => 2008-08-14 14:09:08 > > > > [created] => 2008-08-14 14:09:08 > > > > ) > > > > > ) > > > > > I check if the author already exists. If yes then add it to $this- > > > > > >data : > > > > > Array > > > > ( > > > > [Author] => Array > > > > ( > > > > [nick] => primeminister > > > > [modified] => 2008-08-14 14:09:08 > > > > [created] => 2008-08-14 14:09:08 > > > > [id] => 1 > > > > ) > > > > ) > > > > > But this ID is not used when saving the model Author record. It is > > > > used but the with an INSERT statement. > > > > Query: INSERT INTO `authors` (`nick`,`modified`,`created`,`id`) VALUES > > > > ('primeminister','2008-08-14 14:09:08','2008-08-14 14:09:08',1) > > > > > How can I set this ID when using saveAll in items controller? > > > > > thnx!- Hide quoted text - > > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---