CodeIgniter Forums
Query Join Table In Where Clause Using DataMapper - 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: Query Join Table In Where Clause Using DataMapper (/showthread.php?tid=44065)



Query Join Table In Where Clause Using DataMapper - El Forum - 08-01-2011

[eluser]Vheissu[/eluser]
I am building a simple classifieds system and using DataMapper Overzealous Edition as my ORM of choice. Basically a listing is assigned to a category and I want to be able to query a listing via its category. See below for some code of how I think it would work, is this correct or do I need to instantiate a new "Category" model object as well?

Code:
$l = new Listing();
$l->where('status', 'active');
$l->category->where('name', 'electronics');
$l->get();

Would the above code work for retrieving all listings assigned to the "electronics" category and if not, how would I go about doing this?

Also I am not populating relationships automatically, all relationships to other models are done manually as needed for performance reasons if that helps.