Jeremy Burns
Class Outfit
jeremyburns@classoutfit.com
http://www.classoutfit.com
On 1 Sep 2010, at 08:24, chargu wrote:
> It did not work in Cake when the view does not have a column named
> 'id' or a deceleration similar to var $primaryKey = 'user_id'; in the
> model for Cake to recognise it. (It issues a warning to be precise,
> but I don't usually allow warnings in my code.)
> Note it is also impossible to create a view with duplicated attribute
> names (in PHPMyAdmin).
>
> On Aug 31, 5:57 pm, Jeremy Burns | Class Outfit
> <jeremybu...@classoutfit.com> wrote:
>> No - Cake's convention is a single primary key when working with tables (especially when dealing with a single row), but that needn't restrict you with views so long as the view doesn't have two fields with the same name (e.g. 'id'). If the view is constructed properly you'd have given them aliases anyway, so do a multi-field where clause on them. I'd steer clear of anything other than read activities on a view.
>>
>> Jeremy Burns
>> Class Outfit
>>
>> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>>
>> On 31 Aug 2010, at 08:45, chargu wrote:
>>
>>
>>
>>> 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 <charlotte...@gmail.com> 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
>>
>>>> <jeremybu...@classoutfit.com> 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
>>
>>>>> jeremybu...@classoutfit.comhttp://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.organdhelpothers 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 cake-php@googlegroups.com
>>>>>> To unsubscribe from this group, send email to
>>>>>> cake-php+unsubscribe@googlegroups.com For more options, visit this group athttp://groups.google.com/group/cake-php?hl=en
>>
>>> Check out the new CakePHP Questions sitehttp://cakeqs.organd 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 cake-php@googlegroups.com
>>> To unsubscribe from this group, send email to
>>> cake-php+unsubscribe@googlegroups.com 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 cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
No comments:
Post a Comment