[Dbix-class] Protecting records from update / overloading

Mitchell Jackson mitch.lists at onsitesquad.com
Fri Oct 5 05:06:28 GMT 2007


Friends,

Is there a straightforward way to overload update related methods across 
several classes?

I'm setting a value in a field called "is_locked", and when it is set to 
1, I want to ignore any method calls that might update the database.

I want related tables to also obey the is_locked field from the first table.

I have done this by overloading update, set_column, set_columns and 
store_column. 

I originally tried to create a derivative class of 'DBIx::Class' called 
'DBIx::LockingClass' containing the methods, but because of the 
Class::C3 chain, my overloaded methods in 'DBIx::LockingClass' get 
overloaded somewhere else later, and are rendered useless.

( C3 Inheritance Chain )
DBIx::Class::Core, DBIx::Class::Relationship, 
DBIx::Class::Relationship::Helpers, DBIx::Class::Relationship::HasMany, 
DBIx::Class::Relationship::HasOne, DBIx::Class::Relationship::BelongsTo, 
DBIx::Class::Relationship::ManyToMany, 
DBIx::Class::Relationship::Accessor, 
DBIx::Class::Relationship::CascadeActions, 
DBIx::Class::Relationship::ProxyMethods, 
DBIx::Class::Relationship::Base, DBIx::Class::InflateColumn, 
DBIx::Class::PK::Auto, DBIx::Class::PK, DBIx::Class::Row, 
DBIx::Class::ResultSourceProxy::Table, DBIx::Class::ResultSourceProxy, 
DBIx::ClientClass, DBIx::Class, DBIx::Class::Componentised, 
Class::C3::Componentised, Class::Accessor::Grouped

My current solution was to copy the overloaded methods into each class 
defining a table, to bump them to the front of the Inheritance chain.  
That's a messy approach, because it makes updates to that code 
error-prone, and it gets in the way of other overloads to the same 
functions in a few of my classes.

How have y'all approached this problem?  Am I missing something obvious?

Kind Regards,

/Mitch
OnSite Mobile



More information about the DBIx-Class mailing list