Re: Cake 1.2 isUnique validation

2007-11-30 Thread Ivolution
@MrTufty: The code I posted above should work with both operations (updating and inserting). That's why the code checks if the id is set in the model (hence it's working with an existing row then, and checks all other rows for duplicates of the to-update value). On Nov 30, 2:49 pm, MrTufty <[EMA

Re: Cake 1.2 isUnique validation

2007-11-30 Thread MrTufty
Good solutions Richard, nice one. You may want to look into specifying the 'on' part of the validation rule, which allows you to set whether the validation is done on creating a new record, or updating an existing one. I'm not sure how, if at all, that would tie into the code you've provided here

Re: Cake 1.2 isUnique validation

2007-11-30 Thread RichardAtHome
If anyone else is looking for some drop in code to handle unique validation, here's what I came up with. This is a generic function you can drop into your app_model: /** * checks is the field value is unqiue in the table * note: we are overriding the default cakephp isU

Re: Cake 1.2 isUnique validation

2007-11-29 Thread RichardAtHome
Thanks for the additional feedback. I'd already discovered the 'edit' gotcha and created a workaround similar to Involution's. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group,

Re: Cake 1.2 isUnique validation

2007-11-29 Thread Ivolution
Alternatively (and better because reusable in other Models), you could insert the function _isUnique (documented below) in your own app_model.php and use the following code in your Model. Second argument in the 'rule' array is the field that has to be checked for uniqueness.. var $validate = arr

Re: Cake 1.2 isUnique validation

2007-11-29 Thread francky06l
Take care when using with edit. Indeed you can edit your data, not modifying the field but the field will exist in the DB (the current record)... On Nov 29, 7:54 pm, José Pablo Orozco Marín <[EMAIL PROTECTED]> wrote: > Maybe this help:http://tempdocs.cakephp.org/#TOC121845 > > class User extends

Re: Cake 1.2 isUnique validation

2007-11-29 Thread José Pablo Orozco Marín
Maybe this help: http://tempdocs.cakephp.org/#TOC121845 array( 'rule' => array('checkUnique'), 'message' => 'Login name already taken.' ) ); function checkUnique($data) { $valid = false; if(isset($fieldName) && $this->hasField($fieldN

Re: Cake 1.2 isUnique validation

2007-11-29 Thread RichardAtHome
Ahh, thank you very much Mr Tufty. Another piece of the Cake puzzle slides into place :-) On Nov 29, 4:28 pm, MrTufty <[EMAIL PROTECTED]> wrote: > And is entirely wrong... well, no, it'll work, but it doesn't take > advantage of CakePHP 1.2 validation. The IBM tutorials are good, but > outdated n

Re: Cake 1.2 isUnique validation

2007-11-29 Thread MrTufty
And is entirely wrong... well, no, it'll work, but it doesn't take advantage of CakePHP 1.2 validation. The IBM tutorials are good, but outdated now. Richard, as you suspect, you're not supposed to be referencing isUnique in a rule. But, you don't need to use it in the controller. Here's how you'

Re: Cake 1.2 isUnique validation

2007-11-29 Thread sMAshdot
On 29 Nov., 13:40, RichardAtHome <[EMAIL PROTECTED]> wrote: > As a side note, I suspect isUnique might not meant to be referenced in > a rule and is meant to be referenced in the controller. If this is > true can someone point me towards some examples of how / where it > should be used? I'm quit