Hi everybody,

I've got an issue with the {$__cakeID__$} value in a finderQuery :

I have a Resource model and a Mark model, with these associations :
Resource hasMany Mark
Mark belongsTo Resource

Mark is a simple model with an id, a value and of course a
resource_id. What I'd like to do is, instead of getting all my marks
when fetching a Resource model, to compute the average mark for this
Resource.

So I tried to use the finderQuery param and obviously used {$__cakeID__
$} to get my average calculated with the proper marks :

"finderQuery" => 'SELECT AVG(Mark.value) AS average FROM res_marks AS
Mark WHERE Mark.resource_id = {$__cakeID__$}'

I'm not so sure I can use finderQuery for that, but I bet it's made
for it... the problem is that it generates an wrong query when I try a
$this->Resource->findAll() :

SELECT AVG(Mark.value) AS average FROM res_marks AS Mark WHERE
Mark.resource_id = 1, 2

This is the generated query if I have two Resources of id 1 and 2 in
my database... if I add a new one with id=5, it generates
Mark.resource_id =1, 2, 5...

I don't understand this behaviour, and I've found no one with this
problem... does anyone have an idea on it ? Am I doing something
wrong ?

Thanks a lot,
OLance

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to