Model And Cdbcriteria Returning Null Attributes

Dear all

I’m struggling to understand why my model is returning null values on attributes even when trying to use CDbCriteria.

I have a simple table:

[customer_name, street, city, lat, lon]

At the moment, I only want to return [customer_name, street, city]

If I try use CDbCriteria();

$criteria = new CDbCriteria();

$criteria->select = 'customer_name, street, city';

echo json_encode(Customers::model()->findAll($criteria));

It returns [lat,lon] as null. Even though I don’t want it in the response.

Print the result without json_encode.

You query just for specified attributes but it does not change the fact that the model has also other attributes related to other columns in table which is modelled. Model does not change on every single query, because it must provide some common interface.

You need to manually extract attributes to serialize or mess with model meta-functions (CModel::attributeNames() and so on) so that it returns reduced attribute set…

you can map the array and select the attributes you need

Thanks for all the suggestions. There was some hope with Scenarios, but that has unfortunately not been able to help.

I’ve decided to quit this struggle and just write a straight up use a DAO object to retrieve the results how I want it.