Hi there,
I’ve faced a problem while executing an query using models.
The problem is query returning all fields in model/table instead I’ve selected.
I’ve selected two fields [ id, CONCAT(first_name, ’ ', middle_name) FMName ]
but result returning all fields in table and fields are without values only id field has value. Fields are
I printed these fields by print_r($Results[0]->attributes)
Array (
[id] => 1
[first_name] =>
[middle_name] =>
[last_name] =>
[alt_email_id] =>
[mobile] =>
[contact_address_line_1] =>
[contact_address_line_2] =>
[city] =>
[joining_date] =>
[email_verified] =>
[active] =>
[deleted] =>
)
Please see here
$Results = UserProfiles::model()
->published()
->findAll(array(
'select' => "id, CONCAT(first_name, ' ', middle_name) FMName",
'order' => 'FMName ASC', 'group' => 'FMName'
));
Above published() is a scope defined in UserProfiles as
public function scopes() {
return array(
...
'published' => array('condition' => "active='1' AND deleted='0'",),
...
);
}
And there is also a defaultScope as
public function defaultScope() {
return array(
'condition' => "active='1' AND deleted='0'",
'order' => "last_name ASC",
);
}
But, Interesting is Query I found exact what I’m trying to execute. I found query in web-log
SELECT id, CONCAT(first_name, ' ', middle_name) fmname FROM `tbl_user_profiles` `t`
WHERE active='1' AND deleted='0' GROUP BY fmname ORDER BY fmname, last_name ASC
I executed this query in MySQLand results is actual as need.
Anybody help me about what’s wrong with above scripts or statements