Played around with it, I was less than impressed as Cake does not like composite primary keys, this limits the usage of views greatly. I got around it by borrowing a primary key from one of the base tables and trick cake into thinking it's a proper table with a primary key.
'CakePHP does not support composite primary keys. If you want to directly manipulate your join table data, use direct query calls or add a primary key to act on it as a normal model.' On Aug 31, 9:29 am, chargu <[email protected]> wrote: > Cool thanks for your reply. > > I have also dug around about it for a bit and realise it might not > always be a good idea to do edit/delete on a view (eg, someone else > takes over the project and starts relying on the views as opposed to > the actual tables), but if index and view works I am happy to give > that a try. Will report back :) > > On Aug 31, 3:35 am, Jeremy Burns | Class Outfit > > > > <[email protected]> wrote: > > I have defined views as tables (i.e. set up a model that points to it) and > > it works great for index/view, but edit/delete is dependent upon the > > database and view structure - views are often based on more than one table, > > so are more complex than a single table. > > > Jeremy Burns > > Class Outfit > > > [email protected]http://www.classoutfit.com > > > On 30 Aug 2010, at 09:08, chargu wrote: > > > > Hi All, > > > > Just wondering if there is a way to use database views in CakePHP. > > > > Say I want to have a view > > > > CREATE VIEW user_view_{$user_id} AS > > > SELECT * > > > FROM users, comments > > > WHERE users.id = comments.user_id > > > AND users.id = {$user_id} ; > > > > and I also want to have an adhoc model to CRUD on this view (so that I > > > don't actually need to have a condition 'user_id' = {$user_id} > > > whenever I need the data. I'm lazy, I know :p but this is just a > > > simplified example of my somewhat complicated model). > > > > Is there a way to achieve this? I found very little useful results in > > > Googling for 'cakephp database view', it seems people are quite happy > > > the way it is. Or am I being 'academic' and missing the point about > > > the whole view business? > > > > Thanks in advance :) > > > > Char > > > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others > > > with their CakePHP related questions. > > > > You received this message because you are subscribed to the Google Groups > > > "CakePHP" group. > > > To post to this group, send email to [email protected] > > > To unsubscribe from this group, send email to > > > [email protected] For more options, visit this group > > > athttp://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
