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, but is there a way to do this for a database view?
2
-
It should work fine in the same way as with tables. Just use the view name when you generate the model.Pentium10– Pentium102011-04-25 20:40:04 +00:00Commented Apr 25, 2011 at 20:40
-
Well that was a silly oversight. Thank you. That worked. Answer the question and I'll give you credit.k to the z– k to the z2011-04-25 20:43:13 +00:00Commented Apr 25, 2011 at 20:43
Add a comment
|
2 Answers
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.
Comments
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.
3 Comments
open-ecommerce.org
Not sure why this answer it is marked as correct and has 7 because the active model needs a primary key to work by design and you won't have it in a db you can try the Joshua tip though
Pentium10
@open-ecommerce.org just because Joshua completed 4 years later the answer, and Yii versions have been updated.
jagel.id
Not working, model need primary key, the solution by Joshua is working