Calling a database view in Yii using Active Record

I understand how to query a table with an active Yii writer. I can not find documentation for calling mysql view. In addition, I know how to model a table in an active record using a gii tool, but is there a way to do this to represent the database?

+6
source share
2 answers

It should work just as well as with tables. Just use the view name when creating the model.

Please read Joshua's answer and find out how to add a primary key to the OOP model for views.

+6
source

I do not have the same experience, and this comment is for those who are having problems.

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

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

I solved this by adding ...

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

... to my redefinition of the model.

+2
source

Source: https://habr.com/ru/post/886650/


All Articles