0

I'm working on a demo app to evaluate CodeIgniter for a new project. We are currently reviewing the DataMapper ORM Library - http://datamapper.wanwizard.eu

I've hit a problem that seems odd: I cannot get values from 2 joined tables in one return. I have created models for both tables and verified that I have the $has_many/$has_one set properly. In my controller this code produces an object with all the rows from the named table object:

$job = new Job();
$data['job'] = $job->get(); //produces obj with all rows from table 'jobs'
$acct = new Acct();
$data['acct'] = $acct->get(); //produces obj with all rows from table 'accts'

I have verified both of the above by looping over them with a FOREACH and viewing the data. But when I try to pull related info from both tables. I get nothing. I've tried everything I could find on GET(Advanced) docs. Specifically this is not working:

//NOTE: a job has one acct joined on field 'acct_id'
$job = new Job();
$data['job'] = $job->include_related('acct',array('name'))->get();

The result object ($data['job']) only contains the data from the 'jobs' table.

In my view I'm using this code in a view to see the data:

<table>
<tr><?php foreach ($job->fields as $col) { ?><th><?= $col ?></th><?php } ?></tr>
<?php foreach($job as $row) { ?>
<tr><?php foreach($job->fields as $col) { ?><td><?= $row->$col ?></td><?php } ?></tr>
<?php } ?>
</table>
j08691
  • 204,283
  • 31
  • 260
  • 272
gkl
  • 199
  • 2
  • 11

1 Answers1

1

Please try

$job = new Job();

$data['job'] = $job->include_related('acct',array('name'),TRUE,TRUE)->get();

Detailed Description: http://datamapper.wanwizard.eu/pages/getadvanced.html#include_related

Community
  • 1
  • 1