3

I am using Zend_Validate_Db_NoRecordExists detailed in the link below to check if a record exists before inserting it.

I have no issues with the basic code and have got it working fine, what I need to do next is add a WHERE clause to exclude records where the field recordDelete = 1.

Zebd_Validate_Db_NoRecordExists

Here is a snippet of the code where I'm using this:

$validator = new Zend_Validate_Db_NoRecordExists($options);
$form->getElement('productSTOCKCODE')->addValidator($validator);

Thanks

Yes Barry
  • 9,514
  • 5
  • 50
  • 69
jjmu15
  • 98
  • 8
  • Can you post some of your code? Like the code from wherever you're using `Zend_Validate_Db_NoRecordExists`.. – Yes Barry Dec 09 '11 at 10:03
  • of course $validator = new Zend_Validate_Db_NoRecordExists($options); $form->getElement('productSTOCKCODE')->addValidator($validator); The rest of the code are the classes detailed in the original link. – jjmu15 Dec 09 '11 at 10:12

2 Answers2

4
$validate = new Zend_Validate_Db_RecordExists (array (
    'table' => 'orders',
    'field' => 'id',
    'exclude' => 'recordDelete = 1'
));

$result = $validate->isValid ('000489FS1qT81XR4GWuV');
akond
  • 15,865
  • 4
  • 35
  • 55
1

You could try creating you're own version of it and set the $_exclude member variable.

(Untested)

class My_Validate_Db_NoRecordExists 
    extends Zend_Validate_Db_NoRecordExists // notice what were extending here
{
    protected $_exclude = array(
        'field' => 'recordDelete',
        'value' => 1
    );
}

OR you could just pass the $exclude param along to the constructor wherever you're using it:

$options = array(
    'table' => $yourTable, 
    'field' => $yourField, 
    'exclude' => array(           // <- set exclude here
        'field' => 'recordDelete',
        'value' => 1
    )
);
$dbValidator = new Zend_Validate_Db_NoRecordExists($options);
Yes Barry
  • 9,514
  • 5
  • 50
  • 69