[Solved] Active records Custom culumn

It is possible get custom database column from active record. ex:.

sql:




SELECT CONCAT(Name, LastName) as FullName FROM myTable



ActiveRecord;




$result = $myTable::model()->findAll(array('select'=>'CONCAT(Name, " ", LastName) as FullName'));


foreach ($result as $result) {

    	echo $result->FullName;

}




Is possible, you have just to add a property to the model class.




class myTable extends CActiveRecord

{

   public $FullName;


   [...]




This will work fine. Anyway you can always write a getter method instead, in order to avoid to use the concat (it has not the same syintax on each DBMS):

In the class mytable you can do:




public function getFullName()

{

    return $this->Name.' '.$this->LastName;

}



I prefer the second method, in order to leave all business rule in the model (is not required to set the select statment).

the think is that i need get binary set of column.

this was simplified example of it.

http://dev.mysql.com…t-datatype.html

i want get bin set of my column

mysql> SELECT rowid, myset, LPAD(BIN(myset+0),4,‘0’) AS binset FROM set_test;

the result is .

±------±----------------------------------±-------------+

| rowid | myset | binset |

±------±----------------------------------±-------------+

| 1 | Travel,Sports,Dancing | 0111 |

| 2 | Travel,Dancing | 0101 |

| 3 | Travel | 0001 |

| 4 | Dancing | 0100 |

| 5 | Dancing | 0100 |

| 6 | Sports,Dancing | 0110 |

| 7 | Travel,Sports,Dancing,Fine Dining | 1111 |

| 8 | Travel,Fine Dining | 1001 |

| 9 | Sports,Fine Dining | 1010 |

| 10 | Travel,Dancing,Fine Dining | 1101 |

±------±----------------------------------±-------------+

with my active record class.

You have to add the property, then you can select with:




$criteria=new CDbCriteria;

$criteria->select='rowid, myset, LPAD(BIN(myset+0),4,'0') AS binse';

set_test::model()->findAll();



juppi :) it worked thank you ;)