views:

19

answers:

1

Hi!

I had created the following table method in order to extract some specific table columns to allow later comparison to values stored on arrays:

public function findAllComposedExcelColumns()
  {
    $q = Doctrine_Query::create()
        ->select('p.branch_code, p.state_id, p.state_description, p.account, p.client_name')
        ->from('Process p');

    return ($q->fetchArray());
  }

But when I print an element of the retrieved array, it has also the property id which a don't need.

Array ( [0] => Array ( [id] => 1 [branch_code] => ... [state_id] => ... [state_description] => ... [account] => ... [client_name] => ... ) )

Why the id is also appearing on the results? There is any way to remove it?

Thanks in advance, Best regards!

A: 

Try hydrating with HYDRATE_SCALAR - it might give you what you want.

Eg.

public function findAllComposedExcelColumns()
  {
    $q = Doctrine_Query::create()
        ->select('p.branch_code, p.state_id, p.state_description, p.account, p.client_name')
        ->from('Process p');
    $output = $q->execute(array(), Doctrine_Core::HYDRATE_SCALAR);
    return $output;
  }

edit:

note that this will also change your array keys,

eg from ['branch_code'] to ['p_branch_code']

using this type of hydration method is also not ideal when there are related records.

All in all, the above achieves your goal for this scenario. However, I would agree with DrColossos that it is better to simply loop over and ignore the data you don't want.

So Over It