Strange problem in Relational AR

I am trying to execute the following statement:




$a = A::model()->with(array(

            'b'=>array('select'=>'b.name'),

            'c.d'

        ))->findAll(

        array(

            'select'=>array("t.*, FORMAT(ABS(t.amount), 2, 'en_IN')  as amount_fmt"),

            'condition'=>'id = :id',

            'params'=>array(':id'=>$id)

            ));



The statement executes without any error. But i dont get the columns of the table t, i.e., the table a. Only the following columns of the table a are available:




a->id

a->amount_fmt



For instance, I am not able to retrieve a->amount.

But, if the above statement is executed with a small modification:




$a = A::model()->with(array(

            'b'=>array('select'=>'b.name'),

            'c.d'

        ))->findAll(

        array(

            'select'=>array("`t`.`amount` as `t0_c5`, FORMAT(ABS(t.amount), 2, 'en_IN')  as amount_fmt"),

            'condition'=>'id = :id',

            'params'=>array(':id'=>$id)

            ));



Now, a->amount is available (amount is the sixth column in table a).

Am i doing something wrong in the first statement, because i do not want to remember the column no. to get the correct result?

what about if you don’t include the alias ‘t’ ? have you tried that?




'select'=>array("*, FORMAT(ABS(amount), 2, 'en_IN')  as amount_fmt"),



This does not work…

I found the solution, after a lot of experimentation…

The statement which Antonio high-lighted has to be arrayed in the following manner:




'select'=>array("*", "FORMAT(ABS(amount), 2, 'en_IN')  as amount_fmt"),



So, the overall stmt would be:




$a = A::model()->with(array(

            'b'=>array('select'=>'b.name'),

            'c.d'

        ))->findAll(

        array(

            'select'=>array("*", "FORMAT(ABS(t.amount), 2, 'en_IN') as amount_fmt"),

            'condition'=>'id = :id',

            'params'=>array(':id'=>$id)

        ));