porton
porton

Reputation: 5827

Yii: How to manage changelog for a model?

CREATE TABLE `personchanges` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `person` int(11) unsigned NOT NULL,
  `msg` mediumtext NOT NULL,
  PRIMARY KEY (`id`),
  KEY `person` (`person`),
  KEY `fk_personchanges_1` (`person`),
  CONSTRAINT `fk_personchanges_1` FOREIGN KEY (`person`) REFERENCES `person` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB COMMENT='changelog'

(There is also the table person, but its content is irrelevant for my question, just know that it has id field.)

In the editing form for person I want to display an (always initially empty) textarea.

If before saving (creation or updating) the user types a text in this textarea, this text should be saved into personchanges table.

When viewing (not editing) the person (from person table) among other data should be displayed msg from the last (having the highest id) personchanges row for the given person id.

My question: Where should I implement showing and editing the msg textarea? Should it be in the model (class Person), in the form, wherever?

Upvotes: 2

Views: 325

Answers (1)

darkheir
darkheir

Reputation: 8960

There is an extension performing kind of what you want: Yii model Versioning

SAModelVersioning is a Yii behavior that provides versioning capabilities to any ActiveRecord object.

So you can track allt he changes on your model. The extension provides also some methods to get the last version, compare versions, revert to another version, ...

Upvotes: 0

Related Questions