Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend_Validate_Db_RecordExists against 2 fields

I usualy use Zend_Validate_Db_RecordExists to update or insert a record. This works fine with one field to check against. How to do it if you have two fields to check?

 $validator = new Zend_Validate_Db_RecordExists(
        array(
            'table' => $this->_name,
            'field' => 'id_sector,day_of_week'
            )
    );

    if ($validator->isValid($fields_values['id_sector'],$fields_values['day_of_week'])){
        //true
    }

I tried it with an array and comma separated list, nothing works... Any help is welcome. Regards Andrea

like image 880
cwhisperer Avatar asked May 19 '11 13:05

cwhisperer


1 Answers

To do this you would have to extend the Zend_Validate_Db_RecordExists class.

It doesn't currently know how to check for the existence of more than one field.

You could just use two different validator instances to check the two fields separately. This is the only work around that I can see right now besides extending it.

If you choose to extend it then you'll have to find some way of passing in all the fields to the constructor ( array seems like a good choice ), and then you'll have to dig into the method that creates the sql query. In this method you'll have to loop over the array of fields that were passed in to the constructor.

like image 93
Jerry Saravia Avatar answered Sep 20 '22 10:09

Jerry Saravia