php - Setting a required value in Doctrine model -


is possible set constraint in doctrine model, queries using model include requirement? example, if have car model , want ensure results retrieved using model have active = 1 set in database. define in each individual query, seems there's better way.

cheers!

i take advantage of amazing pre , post hooks inside model.

example:

class model_car extends model_base_car {     public function predqlselect(doctrine_event $event)     {         $event->getquery()->addwhere("active = ?", 1);     } } 

although did not test this, should work. have used pre , post hooks lot make life easier in past. instance, had model wanted save remote_addr on each insert , update, did following make life easier:

class model_example extends model_base_example {     public function preinsert(doctrine_event $event)     {         $this->created_ip = $this->_getremoteip();     }      public function preupdate(doctrine_event $event)     {         $this->updated_ip = $this->_getremoteip();     }      protected function _getremoteip()     {         return ip2long($_server['remote_addr']);     } } 

hope helps!


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -