Re: HABTM find question
Take a look at using the same solution as in the FilterTag example in
the CakePHP book, see:
http://book.cakephp.org/view/1039/Associations-Linking-Models-Together#hasAndBelongsToMany-HABTM-1044
The last example is the one. Maybe it can be applied to your issue :)
Enjoy,
John
On Jun 18, 6:40 am, Roland Pish <rolandp...@gmail.com> wrote:
> Hi!
> I've been struggling with something that I cannot seem to get working.
>
> I have this relationship: Treatment HABTM Symptom
>
> What I want to do is: search treatments by symptom, and the result
> must display treatments fields (id, name, cost, etc).
>
> For now, I've been doing this in treatments_controller.php:
>
> $symptoms = $this->Treatment->Symptom->find('all',array('conditions'=>array('Symptom.name LIKE'=>"%$search
>
> %"))); // $search is the search value that can be a part of a word
> (i.e. "ache").
>
> The first problem is that I cannot "order" that find by Treatment.name
> because it shows the error: unknown field Treatment.name. How can I
> overcome this? How can I include fields of the "original" model table
> in this find?
>
> The other problem is that after executing the above, I have to walk
> into array $symptoms searching (for each symptom) for the sub-array
> $Treatment to get treatments for the current symptom, because that
> "find" gives me an array of symptoms (and not treatments). This is
> kind of uncomfortable because more than one found symptom can have the
> same treatment, so I have to take care of the duplicate treatments
> manually.
> Is there some way to tell "find" to get treatments rather than
> symptoms and include the field Symptom.name in the conditions array?
>
> I really appreciate your help.
>
> Regards.
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
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home