Datamapper: Something like where_in_related, but including all - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Datamapper: Something like where_in_related, but including all (/showthread.php?tid=58203) |
Datamapper: Something like where_in_related, but including all - El Forum - 05-23-2013 [eluser]avramovic[/eluser] Ok, I'm working on a realestate website and I have few tables (of importance here) such as: properties: id, title, desc, price, amenities: id, name amenities_properties: id, amenity_id, property_id Now, within a search there are checkboxes that are used to select amenities that must be present in a property. So, in my controller I had something like: Code: $results = new Property(); This gets all properties that have at least one of the selected amenities, but I need only the properties that have them all! So I thought something like this will solve my problems: Code: $results = new Property(); Unfortunately, this returns no properties in my $results, although I'm sure at least one of them had amenities I tested with. The generated query has no errors but retrieves nothing. Here it is: Code: SELECT DISTINCT `properties`.* Any other ideas how to get properties that have ALL selected amenities related to them? Datamapper: Something like where_in_related, but including all - El Forum - 05-27-2013 [eluser]avramovic[/eluser] OK, I did some research and I've found out that I need to make multiple joins of the amenities_properties table for each checkbox checked... something like this: Code: ... Is this even possible with Datamapper? Or is there another (simpler) way to do this? Datamapper: Something like where_in_related, but including all - El Forum - 05-29-2013 [eluser]avramovic[/eluser] OK, I'm looking like lunatic replying to myself constantly, but here's how I've done it, in case someone else needs similar functionality: Code: $results->where_in_related_amenity('id', $am_ids); |