Page 1 of 1

Custom validation with multiple fields

PostPosted: Sun Oct 23, 2011 6:04 am
by iegroup21
Hello, I have a query regarding custom validation with multiple fields.

I'm trying to check if there are existing records with the same family name and given name in a table containing membership records.

The documentation found here (http://xataface.com/documentation/how-t ... validation) makes it sound like this is only possible with one field. So I would like to know if it is possible to create a validation rule that validates the input of multiple fields?

Thanks.

Re: Custom validation with multiple fields

PostPosted: Sun Oct 23, 2011 11:15 pm
by ADobkin
Perhaps this post might be helpful:

viewtopic.php?t=5503

Re: Custom validation with multiple fields

PostPosted: Mon Oct 24, 2011 11:24 pm
by iegroup21
I have already explored setting the relevant fields in the database as unique but that equates to checking 1st field OR 2nd field for uniqueness but not 1st field AND 2nd field.

For example the database contains the following:

Kerry Smith
John Jackson

By setting the specific fields to unique, if a user types in John Smith, it will run up again the John and Smith in the database even though their is no "John Smith".
Using two "function _validate" in the delegate class also results in the same.

So is there a way to check for the combined uniqueness for multiple fields by using a _validate like function which can call multiple fields.

Thanks in advance.

Re: Custom validation with multiple fields

PostPosted: Tue Oct 25, 2011 9:24 am
by shannah
You can have multi-field indexes in MySQL. Just create a unique index containing both the firstname and lastname columns.

Re: Custom validation with multiple fields

PostPosted: Tue Oct 25, 2011 11:02 am
by iegroup21
Thanks, The answer with the multifield indexes hit me a few hours after my last post.

Re: Custom validation with multiple fields

PostPosted: Fri Jun 01, 2012 9:23 am
by chapin
shannah wrote:You can have multi-field indexes in MySQL. Just create a unique index containing both the firstname and lastname columns.


Hello Steve!
Yes, I tried that. It works fine if I create a unique index on one field. Xataface throws a message telling me it is not possible to insert a repeated value. Then I create a new unique index on two fields. I try to insert a repeated tuple but it is not saved in the database, exactly as it should be expected. The problem is that I get a message like this: "New record created successfully" How can I fix this problem?

Btw Thank you very much for this great piece of software!!!