validation for uniqueness of record

A place for users and developers of the Xataface to discuss and receive support.

validation for uniqueness of record

Postby md9 » Tue Mar 11, 2008 11:18 pm

I am trying to put in some method, so that record inserted must be unique. For example in inventory table, the itemname should be unique i.e. there should not be two entries for Ford_IKON.
This calls for validation by reading values from database table. Validation will not work directly, and only way is to have trigger in delegate class:

Code: Select all
function beforeInsert(&$record){
        *CODE*
    } 

What should this *CODE* include is my question[/code]
md9
 
Posts: 9
Joined: Sat Dec 29, 2007 11:04 pm
Location: India

Postby shannah » Wed Mar 12, 2008 8:30 am

The best way to force uniqueness is in the database schema by adding a unique key.

If that is not an option, they you should probably add a validation method.
http://framework.weblite.ca/documentati ... validation
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby md9 » Thu Mar 13, 2008 8:43 pm

I made the partname as unique key. This although does not help automatically check the uniqueness and throws errors while trying to save the record--which is actually a duplicate entry.

Code: Select all
Fatal error: [pear_error: message="Duplicate entry in table 'part'" code=112 mode= level=notice prefix="" info="On line 101 of file C:\Program Files\xampp\htdocs\dataface\Dataface\Error.php in function printStackTrace()
On line 639 of file C:\Program Files\xampp\htdocs\dataface\Dataface\IO.php in function duplicateEntry(Duplicate entry in table 'part')
On line 354 of file C:\Program Files\xampp\htdocs\dataface\Dataface\IO.php in function _insert(Dataface_Record Object,part)
On line 2058 of file C:\Program Files\xampp\htdocs\dataface\Dataface\QuickForm.php in function write(Dataface_Record Object,)
md9
 
Posts: 9
Joined: Sat Dec 29, 2007 11:04 pm
Location: India

Postby shannah » Fri Mar 14, 2008 6:00 pm

Oh. yes.. This is the right result, just that the error is a little ugly. I had forgotten that the current version of dataface handles duplicate entry errors in an ugly manner.

Until the new version is released you will need to write a custom validator. (see my link in previous post).
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby fantomasdm » Wed Jul 16, 2008 3:03 am

with new version of xataface (1.0 beta3) is possible to add in field.ini
like validators:required = 1 example validators:unique = 1 ??
Or I have to implement a validator for field?
fantomasdm
 
Posts: 114
Joined: Thu Mar 13, 2008 2:35 pm

Postby shannah » Wed Jul 16, 2008 9:42 am

The best way is to make the column unique in mysql. Other than that you would have to do a custom validation method.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 29 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved