My program is using the WanWizard DataMapper ORM with CodeIgniter, and needs to perform a simple query based on a field in a join table. Here is my code:
$d = new Deal();
$deals = $d
->where_join_field('networks', 'status', 'active')
->get();
Fairly straightforward, as you can see. A many-to-many relationship between “deals” and “networks”, with a “status” field in the join table. However, this is the query it generates:
SELECT * FROM (`deal`) WHERE `deal_network`.`status` = 'active'
Obviously, this doesn’t work at all, because there in no JOIN in place to introduce the deal_network table. I tried using include_related, but it aliases the deal_network table as networks_deal_network, resulting in an incorrect table reference. How can I get DataMapper to JOIN that table into the query properly?
It appears that this is table name bug in
_join_fieldinlibraries/datamapper.php. I forked and submitted a pull-request with the fix.https://bitbucket.org/jonahbron/datamapper