CakePHP: Is it possible to associate a model with a database view instead of a table?

Yes its 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 superfast database query which then plugs nicely into cake's world of pagination/sorting on one table which works like a charm.

It's not possible to insert into a view (that I know of, but you know what they say about assumptions), so provided you're just wanting to read data from the view and insert using a model(s) associated with the actual table(s), then it should work.

If you use the property var $useTable in the Model you should be able to use a view. I have not tried it but I'm pretty sure it would work, but of course you cannot insert into it.

Yes, it's possible. And very useful, sometimes.

I'm not familiar with CakePHP but generally frameworks like this should treat Tables and Views as identical so I don't see why this wouldn't work.

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.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions