1
是否有向Phalcon嚮導功能添加附加條件的選項hasManyToMany?我已經檢查了phalcon docs,但他們沒有列出hasManyToMany的所有可能選項(僅列出了別名和foreginKey)。 如果這不能用hasManyToMany完成,是否有其他Phalcon選項可用 - 例如。檢索所有,然後過濾一些模型加載事件?Phalcon模型與附加條件具有多種關係
簡單示例: 我有3個表組,關係和用戶,並希望使用關係表在用戶模型中創建兩個屬性 - active_groups和inactive_groups。
代碼:
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!
TNX的答覆。最後,我們實施了這個解決方案......雖然hasManyToMany中的條件會更酷 – zac
這真的是一個好主意。非常感謝你 ! –