views:

304

answers:

6

I was wondering if it was possible to create a view in a database then be able to link a Model to it?

A: 

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.

Toby Allen
+1  A: 

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.

inkedmn
+1  A: 

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.

jimiyash
A: 

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

A: 

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.

Mołot
A: 

$useTable didn't work...Is the cake php treating tables and views differently? Is there any other way to associate model to a view?

Biju