DataMapper: count on more than one related object - 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: count on more than one related object (/showthread.php?tid=51650) |
DataMapper: count on more than one related object - El Forum - 05-11-2012 [eluser]Genki1[/eluser] For an already retrieved object, is there a "built-in" function to count the number of related objects from multiple relationships? DataMapper has a nice function to count a single relationship (http://datamapper.wanwizard.eu/pages/count.html#Counting.Related), but I'd like to count on more than one relationship. For example: User (1:M) Profiles (M:1) Converters Each User can have multiple Profiles for a single Converter. After retrieving a Profile, I want to know how many Profiles the User has for that same Converter. So far, my solution is: Code: // get Profile by ID Is there a simpler/more elegant/concise way to accomplish this? DataMapper: count on more than one related object - El Forum - 05-12-2012 [eluser]WanWizard[/eluser] Not really simpler or more elegant, but probably faster since it's only two queries: Code: $p = new Profile(); DataMapper: count on more than one related object - El Forum - 05-12-2012 [eluser]Genki1[/eluser] Thank you -- I'll take the speed improvement. And, I'm feeling good that I'm getting the hang of DataMapper :-) |