AR模型玩家:
public function scopes()
{
return array(
'proleague' => array(
'condition' => 'mode = "proleague"',
),
'main' => array(
'condition' => 'mode = "main"',
),
);
}
使用模型播放器:
Player::model()->
proleague()->
with('startposition')->
findAllByAttributes(... here some condition ...);
^^^ 没关系。范围条件将被执行。但是...
在我的项目中,有很多地方没有指定玩家模型的范围,在这种情况下,我需要使用这个范围条件作为默认值:
'main' => array(
'condition' => 'mode = "main"',
)
如果我像这样将 defaultScope() 方法添加到 Player 模型
public function defaultScope()
{
return array(
'condition' => 'mode = "main"',
);
}
下一个代码
Player::model()->
proleague()->
with('startposition')->
findAllByAttributes(... here some condition ...);
无法正确运行。我不会得到 mode = "proleague" 条件,因为我将使用 defaultScope() 和 mode = "main"。 p>
有什么建议吗?我该如何解决这个问题?
最佳答案
您应该只使用 resetScope(true)方法。它“删除”defaultScope 过滤器。
$model = Player::model()->resetScope(true)->proleague();
关于php - Yii 1.1 中的默认范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29817435/