Listening to changes in many_many relationships, but not hack the framework...

I wanted to add logging but changes to the relationships wasn't obvious at first and then I remembered I could overide the class managing the relationships...

Object::useCustomClass('ManyManyList', 'MyManyManyList', true);

 

With a class that did the logging at the same time as managing the relationship...

class MyManyManyList extends ManyManyList {

	public function add($item, $extraFields = null) {
		parent::add($item, $extraFields);

		if(!$this->IgnoreFromSaving()){
			//do logging
		}
	}

	public function removeByID($itemID) {
		if(!$this->IgnoreFromSaving()) {
			//do logging
		}
		
		parent::removeByID($itemID);
	}

	public function removeAll() {
		if(!$this->IgnoreFromSaving()){
			//do logging
		}

		parent::removeAll();
	}
}

us

ing a custom class as a wrapper to allow us to log, but not hack the framework...

 

Object::useCustomClass('ManyManyList','MyManyManyList',true);

 

 

classMyManyManyListextendsManyManyList{publicfunction add($item, $extraFields =null){
		parent::add($item, $extraFields);if(!$this->IgnoreFromSaving()){//do logging}}publicfunction removeByID($itemID){if(!$this->IgnoreFromSaving()){//do logging}
		
		parent::removeByID($itemID);}publicfunction removeAll(){if(!$this->IgnoreFromSaving()){//do logging}

		parent::removeAll();}}
Rate this post (2 rating(s))

Post your comment

Comments

No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments