made. In fact in some circumstances Containable creates unnecessary
queries (https://trac.cakephp.org/ticket/5864).
To be clear, I have no trouble getting my data. It's just, from a
perspective of someone who handwritten his MySQL queries, CakePHP
could be much more efficient with its database calls.
At points I'm a bit torn between writing an app that prioritizes
efficient database queries or Cake's logic. To illustrate:
Option 1:
$data = $this->Article->read();
<queries made (aside from DESCRIBE): 1 + [num_comments]>
Option 2:
$this->Article->recursive = -1;
$articleData = $this->Article->read();
$postData = $this->Article->Comment->find('all', array('conditions' =>
array('Comment.article_id' => $this->Article->id)));
<queries made (aside from DESCRIBE): 2)>
Option 1 is nice and clean, as you would expect from Cake, but it can
potentially mean a lot of database quering. Option 2 on the other hand
doesn't look as slick. It puts some logic in my controller I don't
want there. The related data is split over 2 variables. But the number
of queries is fixed.
I'm just curious if this issue also bothers other developers and what
direction do they choose.
-Roel
On 30 jul, 19:14, JamesF <usaexportexpe...@gmail.com> wrote:
> have you tried using Containable behavior?
>
> On Jul 30, 12:16 pm, Roel <roel....@gmail.com> wrote:
>
>
>
> > Hi,
>
> > I'm using CakePHP for quite some time now and I really love it, but I
> > hadn't come around to make use of the complex association
> > possibilities for models. So I started to play around with them for a
> > personal project I just started. Although the advantages Cake offers
> > are numerous, I stumbled across an issue I'm not happy about. It's not
> > a bug but an effciency issue.
>
> > Let's say we have three models: Article, Comment, and User. The
> > relationships are as follows: Article hasMany Comment, Comment hasOne
> > User. Now when the data for Article is retrieved, a nice JOIN query is
> > used to fetch the Comment data together with the Article data, but a
> > seperate query is made for each User instead of using a nice JOIN
> > statement.
>
> > Now I know this is a known issue (https://trac.cakephp.org/ticket/
> > 2931) and I understand why the resolution is set to 'wont fix', but I
> > wondered how other people worked around this or maybe didn't even
> > bother. Truth is, in this specific case of my personal project it
> > doesn't even matter that much. It doesn't need to serve thousands
> > users. But it bothers me that Cake, which first enabled me to
> > elegantly develop applications fast, now kinda shows it's dirty side.
>
> > So what are your thoughts about retrieving data efficiently with Cake?
--~--~---------~--~----~------------~-------~--~----~
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