![]() |
DataMapper ORM v1.8.1 - 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 ORM v1.8.1 (/showthread.php?tid=42440) |
DataMapper ORM v1.8.1 - El Forum - 07-12-2011 [eluser]lefoup[/eluser] [quote author="Nicolas L.A." date="1309461292"][quote author="WanWizard" date="1309460126"]Yes, that is exactly what I mean. See http://datamapper.wanwizard.eu/pages/joinfields.html.[/quote] Thank you. Despite reading your user guide I didn't find this page. I was expecting the information in the "General Topics > Setting up Relationships" page rather than the current separate one under "Relationships > Working with Join Fields".[/quote] That is really helpful, thanks so much for posting the link!! DataMapper ORM v1.8.1 - El Forum - 07-12-2011 [eluser]WanWizard[/eluser] @Colm Ward, Expect more misery now that the devs are very busy making the core inaccessable to third party solutions. I'm contemplating stopping with DM's support for 2.0.2+ and reactor at the moment, until they've sorted out their mess. And to quit if they don't... DataMapper ORM v1.8.1 - El Forum - 07-12-2011 [eluser]sqwk[/eluser] Does datamapper queue relationships? As in when I load multiple 'rows' from the DB into an object and then tell dm to load a subobject for all rows, will it use multiple queries or collect the child IDS and write one query? DataMapper ORM v1.8.1 - El Forum - 07-12-2011 [eluser]Andy78[/eluser] I'm having a bit of a mental block here: I have two tables users and a related user_types table which has 3 fields id, user_type and access_area. How do I get the users and their related user_type in the following function and feed this into the get_paged? Code: function user_manager($page = 1, $sort_by = 'username', $sort_order = 'asc') DataMapper ORM v1.8.1 - El Forum - 07-13-2011 [eluser]WanWizard[/eluser] [quote author="sqwk" date="1310529768"]Does datamapper queue relationships? As in when I load multiple 'rows' from the DB into an object and then tell dm to load a subobject for all rows, will it use multiple queries or collect the child IDS and write one query?[/quote] Can you please be more specific? In short, every get() is a query. DataMapper ORM v1.8.1 - El Forum - 07-13-2011 [eluser]Flyingbeaver[/eluser] [quote author="Flyingbeaver" date="1309964137"][quote author="WanWizard" date="1309958773"]It's not entirely clear to me what you exactly want. Could you create a dummy array and var_dump it, so I can see what kind of structure you're looking for?[/quote] Sure ! Code: array ( So in my database I have the table service in this way : Code: Services And the relationship table : Code: Related_services_services Si I would like to get the array at the top of the post but also be able to get the parent service of service (if it exists). Thx so much for your help.[/quote] HI Any idea about this one plz ? DataMapper ORM v1.8.1 - El Forum - 07-13-2011 [eluser]WanWizard[/eluser] @Andy78, Code: $users->user_type->get(); doesn't do anything, as at that moment, the $users object is empty (you haven't done a get yet). Besides that, you can't do something like that. Relationships live in a three dimensional space, where as query results are two dimensional. If you want the result of a relationship in a single query, you have to flatten it using include_related(), which will include the fields of the related table in the SELECT using a JOIN. $user->user_type->get() will only get the user_type of the user currently present in the object, not of all retrieved objects. DataMapper ORM v1.8.1 - El Forum - 07-13-2011 [eluser]WanWizard[/eluser] @Flyingbeaver, Same answer as to @Andy78: You can do that for a single object (service), but to do that for a list, you'll have to iterate, or use the model's auto_populate feature to automatically get related objects. Code: // create the service object Note that this will fire one query for the services, and one for EVERY related object. Which is why this is disabled by default, as it can be a massive performance hit, and possibly run you out of memory. DataMapper ORM v1.8.1 - El Forum - 07-13-2011 [eluser]Flyingbeaver[/eluser] Ok i was "dreaming" for a super massive easy ONE query ![]() Thx for the answer. DataMapper ORM v1.8.1 - El Forum - 07-13-2011 [eluser]WanWizard[/eluser] You can only do this in a single query for has_one relations, as you will have to "flatten" the relationship, using include_related(). This doesn't work for has_many (you can't construct such a query, even not manually). |