add column to select object zend framework

1.4k Views Asked by At

Here is my current code:

$Select=new Select();
$Select->from($this->getTable());

What I want now is to add the id column but as DT_RowId instead of id. How do I accomplish this? The goal would be to have all of the table columns as well as this new column.

2

There are 2 best solutions below

0
akond On BEST ANSWER

If you need both "old" and "new" fields, don't forget to add an asterisk.

$Select=new \Zend\Db\Sql\Select();
$Select->from($this->getTable());
$Select->columns([
  '*', 
  'DT_RowId' => 'id',
  'furtherColumn' => 'furtherColumn'
]);
0
aktsh On

The simplest soloution would be to use the columns function with an associative array with aliases as the keys for example:

$select=new Select();
$select->from($this->getTable());
$select->columns(array(
 'DT_RowId' => 'id',
 'furtherColumn' => 'furtherColumn',
));