views:

18

answers:

1

I am trying to use a query with a calculated field in a Yii Relationship definition but all I get is errors.

Here is my query: $me = new CDbExpression('CONCAT_WS(\', \', last_name, first_name) AS the_name');

Here is my relation: 'author' => array(self::BELONGS_TO, 'Author', 'auth_id', 'select'=>$me),

My problem seems to be that CDbExpression is expecting a parameter but the query requires no parameters!?!?!?

I'm getting an Error 500 "trim() expects parameter 1 to be string, array given" (because I have no parameter!?!).

If I add a fake parameter: $me = new CDbExpression('CONCAT_WS(\', \', last_name, first_name) AS the_name',array('test'=>'test')); I get the same error message.

What am I doing wrong?

A: 

It sounds like trim() is getting passed an array instead of a string. The "param" referred to isn't the "params" array passed into CDbExpression as the second parameter, but rather the single param passed in to trim().

Could CDbExpression be returning an array instead of a string to the "select" clause in your author relation? I would verify that $me is a string, and not an array.

Also, where is trim() being called? This might shed some light on the subject as well. Turn on all your error reporting to get the file and line number. There are a few places in the DB code where trim() is called.

thaddeusmt