Question

I has a table name "Account". It has three columns named "Id", "Name", "primary_user_id". I want to show id, name and name corresponding to user id. I mean I have t use left join. I get collection using

$data['accounts'] = Model_Account::find('first', array(
  'related' => array(
    'accounts' => array(
        'join_type' => 'inner',
        'where' => array(
            array('primary_user_id',  'id')
        ),
        'order_by' => array('id' => 'desc'),
    ),
  ),
));

In model:-

 protected static $_has_many =array('accounts');

In view:-

<?php foreach ($accounts as $account): // echo "<pre>"; print_r($users);?>
<tr>
     <td><?php echo $account->id; ?></td>
     <td><?php echo $account->name; ?></td>
         <td></td>  
</tr>
<?php endforeach; ?>

I am trying to get value of name corresponding to primary_user_id. Please help me how can I achieve it.

No correct solution

OTHER TIPS

If you are using the ORM you should not be manually constructing your queries like that. You will want to set up a relation between your Account and User models. There is plenty of documentation about relations in the main fuelphp docs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top