How To Add A Column Alias Into Yii Active Record Model?

n my old project I used long id for table primary key, like ‘shop_id’ or ‘order_id’, but now I want to use just ‘id’ as alias for ‘shop_id’. How to add this to the model class only, not changing tables. After that I’d like to have something like this

$model->id = $var



I don’t think it’s possible to use aliases for column names in Yii. In PostgreSQL you could use a view with some rules defined so you could perform insert/update/delete statements on it that would update some other table. I don’t know if it’s possible in MySQL.

Yes, I use PostgeSQL in ALL my projects. I think it’s a good idea to use db features.

So check out the docs on how to create rules so the view can be updated. From version 9.3, PostgreSQL will allow simple views (selecting from one table) to be automatically updateable.