We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

need flat simple resultset from multi table query

suppose I do

$resultset = $this->getDi()->get('modelsManager')->executeQuery("
    SELECT a.*, b.image FROM ModelA a LEFT JOIN ModelB b
");
foreach ($resultset as $row) {
  var_dump($row);
}

I get:

array (size=2)
  'a' => object(ModelA)
    protected 'col1' => string 'col1val',
    protected 'col2' => string 'col2val',
    ...
  'image' => string 'imgval'

However I need to pass this to a view:

array(
  'col1'=>'col1val',
  'col2'=>'col2val',
  ...
  'image'=>'imgval'
)

I can pre process the data to force it into the new format but then the data is looped though twice, once for the prep and once for the view output.

Or I could just do $resultset = ModelA::find() and force the guy who does the views to understand database table relationships to get the ModelB::image per row however this requires the frontend guy to learn things he shouldn't have to know and would result in many extra queries being executed (one per row) than should be required.

Is there not a way to get a simple combined resultset from a multi table query?

I understand the value in that this way I could make changes to a and save .. but in this case I only want to output data.

Hydrate mode or select columns which you need.

Thanks for your reply however ->setHydrateMode() does not seem to help any.

if i setHydrateMode(Resultset::HYDRATE_ARRAYS) for example I just get this:

array (size=2)
  'a' => 
    array (size=6)
      protected 'col1' => string 'col1val',
      protected 'col2' => string 'col2val',
      ...
  'image' => string 'imgval'

It seems to be the a.* that is the issue, if i list the columns I need such as a.col1, a.col2, b.image then I get the kind of resultset I'm looking for .. but if someone knows how I could have got this while using a.* I would like the answer still. Thanks!