Page 1 of 1

validation for uniqueness of record

PostPosted: Tue Mar 11, 2008 11:18 pm
by md9
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]

PostPosted: Wed Mar 12, 2008 8:30 am
by shannah
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

PostPosted: Thu Mar 13, 2008 8:43 pm
by md9
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,)

PostPosted: Fri Mar 14, 2008 6:00 pm
by shannah
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).

PostPosted: Wed Jul 16, 2008 3:03 am
by fantomasdm
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?

PostPosted: Wed Jul 16, 2008 9:42 am
by shannah
The best way is to make the column unique in mysql. Other than that you would have to do a custom validation method.

-Steve