Phalcon model hasManyToMany relation with additional condition -
is there option add additional conditions phalcon wizard function hasmanytomany? i've checked phalcon docs not list possible options hasmanytomany (alias , foreginkey listed). if cannot done hasmanytomany there other phalcon option available - eg. retrieve , filter on model load event?
simple example: have 3 tables group, relation , user, , use relation table create 2 properties in user model - active_groups , inactive_groups.
code:
class groupmodel extends model { public $id; public $name; } class relationmodel extends model { public $id; public $related_id_one; public $related_id_two; public $active; } class usermodel extends model { public function initialize() { $this->hasmanytomany( "id", "relationmodel", "related_id_one", "related_id_two", "groupmodel", "id", array( 'alias' => 'active_groups', 'conditions' => 'relationmodel.active = true') ); $this->hasmanytomany( "id", "relationmodel", "related_id_one", "related_id_two", "groupmodel", "id", array( 'alias' => 'inactive_groups', 'conditions' => 'relationmodel.active = false') ); } }
tnx!
you instead. btw not entirely sure if code runs idea hopefully.
i don't know if phalcon has conditions / option or not
class groupmodel extends model { public $id; public $name; } class relationmodel extends model { public $id; public $related_id_one; public $related_id_two; public $active; } class usermodel extends model { public function initialize() { $this->hasmanytomany( "id", "relationmodel", "related_id_one", "related_id_two", "groupmodel", "id", array( 'alias' => 'groups') ); } public function getactivegroups() { return $this->getgroups('relationmodel.active = true'); } public function getinactivegroups() { return $this->getgroups('relationmodel.inactive = false'); } }
Comments
Post a Comment