CActiveRecord column mapping

I've got a new Yii application I'm writing but it needs to interface with an old database with gross column names which also has another application using it. I don't want to infest my nice clean new Yii app with those column names and would like to change them once I have finished migrating all functionality from the old app into the Yii app.

Is there a feature in Yii to do column mapping in Yii, like in Prado?

Yii will NOT support column mapping for the same reason that the framework should be clean and simple.

I understand that you don't want to see those ugly column names in your Yii application. The fact is that your database schema is really part of your application (that is its column namings are just like your variable namings). If you are dealing with a legacy system, you won't try to rename all its variables, will you?

You may do something to alleviate your problem. For example, if the database supports views, you can define some views to make the names look nicer.

extend active record and add mapping support there. That will work faster, than creating views. They are usually expensive from the performance point of view.

By the way, maybe you’ll package your new Mapping AR as an extension ;)

You could create get'ers and set'ers in your model class that have nice names that sets the model's attributes.

Let's say your table have a column named 'uglyName' and you wish to refer to is using 'name' instead.

Something like this:



class Person extends CActiveRecord


{


  .....





  public function getName() {


    return $this->uglyName;


  }





  public function setName($name) {


    $this->uglyName = name;


  }





}


That would work like a mapping. When you rename the 'uglyName' attribute in the database to 'name', you could remove the getName end setName functions and the app should continue working with the new column name.