Hi All,

I've been reading the posts and playing around with HABTM. I thought I
was close, but I'm noticing that I'm using a lot of hack code to
accomplish something I think should be easier. Just thought I'd check
here before I make a mess of my whole app.

I've got 3 main tables: conditions, remedies and ratings. There is
also an 'association' table, conditions_remedies which just holds two
fields (condition_id, remedy_id) to link the conditions & remedies.

My models are currently setup up as follows:

condition 'hasAndBelongsToMany' remedy
remedy 'hasAndBelongsToMany' condition
rating 'belongsTo' remedy
remedy 'hasMany' rating

When users are browsing remedies, they get a list of the associated
conditions. When they select a condition, I pass the condition id in
the url... like /mysite/remedy/view/1?condition=2. That way, I can
list all of the ratings that have remedy_id = 1 and condition_id = 2.

In my ratings controller, I have a listbyRemedy function that calls:
$this->set('rating', $this->Rating->findAll($criteria, null,
'Rating.created DESC', $limit, $page, 3));

So, I'm getting the proper info in $rating, but when I look at
$remedy, I am getting results for EVERY row in  conditions_remedies
that matches the condition_id, when I really just want the single row
that matches the condition_id AND remedy_id. Getting so many
conditions back is also causing it to select all ratings for those
conditions regardless of the remedy.

I hope this makes sense to someone. Any help would be greatly
appreciated.

There is a post here that is almost identical to what I'm looking for,
but the link is broken. If anyone knows where to find the info in the
link, I would greatly appreciate an updated link.

<a href="http://groups.google.com/group/cake-php/browse_thread/thread/
895ad34e2b0ddc76/0c81b15a138238c9?lnk=gst&q=habtm
+subqueries&rnum=1&hl=en#0c81b15a138238c9"> Model->findAll() based on
conditions for an associated HABTM model - any progress?</a>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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