CActiveRecord with attributes and attribute values from other tables


I’ve been using Yii for a couple of years now, and I’ve always used the CActiveRecord in an “easy” way (the attributes of the model are the columns of a mysql database table). I’m now stuck because for a larger project, I need to use another database architecture, and I don’t see how to implement it with YII. I’ve read the whole CActiveRecord page in the Yii docs, but I’m still not sure what is the most elegant way to be able to use my model like before (functions like Model->findAll(…), Model->save(), Model->validate(), Model->attribute_name, … ).

Table Profile (id, project_id, createtime)

Table ProfileFields (id, project_id, var_name, […] )

Table ProfileFieldValues (profile_id, profile_field_id, value)

All the attribute names of my Profile Model (except for id (PK) and project_id) are saved in the ProfileFields table (var_name is the attribute name, could be for example "firstname"), and the value of the attributes are stored in ProfileFieldValues table (value is the attribute value, could be for example "Steve").

This kind of architecture is needed because a profile will have different attributes depending on the project it belongs to.

Can someone help me to get started with this?

Thanks so much!