Yii Framework Forum: Historizing ActiveRecords - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Historizing ActiveRecords Save ActiveRecords historized Rate Topic: -----

#1 User is offline   sbernard 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 10-January 11

Posted 16 January 2011 - 10:29 AM

You can use this class to save ActiveRecords historized, which means
we dont do any updates or deletes.
On delete the deletedColumn is set to mark the record as deleted.
On update a new record is created an the old record is marked as deleted.

Create a table like the following:
CREATE TABLE customer (
id INT NOT NULL AUTO_INCREMENT, -- name of this column is optional
itemId INT, -- name of this column is itemId by default but can be set to whatever you like
-- your columns here
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- column is optional
deleted TIMESTAMP NULL DEFAULT NULL, -- name of this column is itemId by default but can be set to whatever you like
PRIMARY KEY (id),
KEY (itemId),
);

Hope you like it.

Attached File(s)


0

#2 User is offline   sbernard 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 10-January 11

Posted 17 January 2011 - 09:21 AM

I made some improvements:
- In default scope, records are ordered ascending by their itemId and not their primaryKey.
- After saving a new record, itemId is set in the model automatically (analog to the primaryKey which is also set in the model after saving the record)

Attached File(s)


1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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