开发者

Calling a database view in Yii using Active Record

I understand how to query a table with Yii's active record environment. I can't find documentation for calling a mysql view. Also, I know how to model a table in active record with the gii tool, b开发者_运维问答ut is there a way to do this for a database view?


I am not having the same experience and this comment is for those who are having trouble.

Using a mysql view with some joins and calculations I get the following error..

app\\models\\db\\WarComplete must have a primary key.

I resolved this by adding...

public static function primaryKey()
{
    return ['id'];
}

... to my model override.


It should work fine in the same way as with tables. Just use the view name when you generate the model.

Please read Joshua's answer and learn how to add primary Key into the OOP model for views.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜