Querying HABTM associations by array
I'm trying to search for profiles based on communities that they HABTM. I need to use an array for the search, because I'll be including dozens of other criteria in the search. I've got everything else hammered out except how to search this way using HABTM assoc's. I've tried tons of combos of binding models, etc to try to get what I'm looking for, but I can't seem to get it right. Here's the code I'm using to try to test just this one aspect of the array search: function test() { $search = array(); $search['Community.title'] = Wally's Home Community; $this-Profile-bindModel(array('hasMany' = array('CommunitiesProfile' = array('foreignKey' = 'profile_id'; $this-Profile-bindModel(array('hasOne' = array('Community' = array('foreignKey' = 'CommunitiesProfile.profile_id'; debug($this-Profile-findAll($search)); debug($this-Profile-findCount($search)); exit; } This particular incarnation of the code yields: Unknown column 'Community.CommunitiesProfile.profile_id' in 'on clause' for the findAll call, and Unknown column 'Community.title' in 'where clause' for the findCount call. Can anyone please help steer me in the right direction? How should I structure the search array, and how do I bind these models to get the results I'm looking for? On IRC people kept telling me to debug() and pr() the results... This doesn't help me figure out how to structure this type of query (though I have tried $search['Profile']['Community']['title'] = 'title', which is what the structure would have led me to believe was the way to go). Thanks --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Querying HABTM associations by array
Just a follow up -- I got the HABTM code linked up following advice from this post: http://groups.google.com/group/cake-php/browse_frm/thread/f23b1825050ad543/014092749592de70?lnk=gstq=filtering+habtmrnum=1#014092749592de70 The working test code is something like this: function test() { $search = array(); $this-Profile-Community-unbindAll(); $comm = $this-Profile--Community-findByTitle(Wally's Home Community); $search['CommunitiesProfile.community_id'] = $comm['Community']['id']; $this-Profile-bindModel(array('hasOne' = array('CommunitiesProfile')), false); // If you don't include the false, you need to execute this line again before doing the count query0 debug($this-Profile-findAll($search)); debug($this-Profile-findAll($search, array('count(*)'))); exit; } Obviously, this code doesn't do much, just tests that I can get the results I want, and a count of the records, since I'll be using paginated results. Thanks to AD7six for putting me onto the right search terms for the google group (filtering habtm). --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---