I was wondering if it was possible to create a view in a database then be able to link a Model to it?
6 Answers
Yes it's possible.
Create the view as if it were a table and make sure that it adheres to all the cake rules for creating tables. Then you can create a model, controller and view as you would with any other Table. It even comes up in the cake bake app as a normal Table.
One of the nice things I found was when dealing with pagination/sorting across a very normalised database, cake becomes almost impossible to deal with. Thus you can combine all your complex joins into one database query which then plugs nicely into cake's world of pagination/sorting on one table which works like a charm.
Comments
In Postgresql it is possible to make insert-able view and non-insert-able table. The only real difference is that table contains it's data, and view selects it. However, you can even make table to select part of it's apparent data from other tables. That said - it seem to me that cake has troubles with treating views just as tables - but that's an arbitrary decision, not a need.