Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

How To Exclude Model Attributes From Being Saved

$
0
0
I'm looking for an elegant way of ignoring table columns in the CActiveRecord model. More precisely, the underlying database is MySql and the table "user" uses a timestamp column like this:

CREATE TABLE user (
  user_id INT NOT NULL AUTO_INCREMENT,
  ...
  ts TIMESTAMP NOT NULL
)


The value of the timestamp column is modified by MySql on every insert (of course) and update which is exactly what I want. However, when the update is performed not via SQL but using the Yii based application, then the timestamp is never updated because the column (as any other column) is considered being part of the CActiveRecord, the current value is read on reading the data and since this field is never changed in the Yii app, it is later written with the same (unchanged) timestamp to the database.

So, MySql would update the timestamp, but because the CActiveRecord includes the column with every update, it is overwritten by the original value. This basically means that the timestamp column is only filled on create but never changes on any further update.

How can I tell the CActiveRecord to exclude this column from being written when the model is saved?

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>