finderQuery result not merging?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

finderQuery result not merging?

Morris-2

Hello

I'm trying to use finderQuery for a hasMany relationship between tables
in cake to get Ratings automatically when I view an Entry.. anyhow, I
use this:

var $hasMany = array (
                        'WikiRating' => array (
                                'className' => 'WikiRating',
                                'foreignKey' => 'entry_id',
                                'dependent' => true,
                                'exclusive' => true,
                                'finderQuery' => 'SELECT ( SELECT count(*) FROM wiki_ratings AS
WikiRating WHERE WikiRating.entry_id = {$__cakeID__$} ) AS num_votes,
AVG(WikiRating.rating) AS avg_rating FROM wiki_ratings AS WikiRating
WHERE WikiRating.entry_id = {$__cakeID__$} LIMIT 1'
                        )
);

but am getting an odd error which causes an error in dbo_source:

Notice: Undefined index: WikiRatings in c:\documents and
settings\morris\Desktop\houseparty_alpha\alpha_build_svn\web\cake\libs\model\datasources\dbo_source.php
on line 709

Notice: Undefined index: WikiRatings in c:\documents and
settings\morris\Desktop\houseparty_alpha\alpha_build_svn\web\cake\libs\model\datasources\dbo_source.php
on line 716

After a closer look, it seems like the query is executing OK but the
result it is getting is [0][0][num_votes]  and [0][0][avg_rating]...
which when merging cake doesnt like, since it is looking for
[0][ModelName][...] etc..

SO, I'm wondering if any of you may have run into something like this,
or know how I can force my result to work as cake wants it.

Thanks!


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: finderQuery result not merging?

the_woodsman

I think this'll be because you use the query:

SELECT count(*) FROM wiki_ratings

Whereas you have to alias the table name to the controller name,
'WikiRatings' or somesuch...  see the debug SQL output of other Cake
queries for how it's done.

I've had similar issues with the findBy methods.

Hope that helps!


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: finderQuery result not merging?

Morris-2

thanks! really appreciate the help..

I can't pick out what I'm missing from the debug sql output...

SELECT count(*) AS num_votes, AVG(WikiRating.rating) AS avg_rating FROM
wiki_ratings AS WikiRating WHERE WikiRating.entry_id = {$__cakeID__$}
LIMIT 1

The above as the finderQuery doesn't work... yet if I take out the
count(*) it works fine (though missing count, which I'd like). So as
far as I can tell the aliasing is all OK, given that it works without
count(*).

maybe I'm missing something apparent?


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---