Yii Framework Forum: CActiveRecord column mapping - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

CActiveRecord column mapping Rate Topic: -----

#1 User is offline   ShabbyRobe 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 13-October 08

Posted 03 December 2008 - 07:15 AM

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?

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,907
  • Joined: 04-October 08
  • Location:DC, USA

Posted 03 December 2008 - 07:49 AM

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.

#3 User is offline   KJedi 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 381
  • Joined: 19-October 08
  • Location:Nikolaev, Ukraine (Europe)

Posted 03 December 2008 - 08:07 AM

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 ;)

#4 User is offline   rsubsonic 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 08-October 08
  • Location:Norway

Posted 03 December 2008 - 08:44 AM

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.

Share this topic:

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users