[CDBI] re-casting cdbi classes?

Matt S Trout dbix-class at trout.me.uk
Thu Mar 23 01:33:48 GMT 2006

William Ross wrote:
> On 18 Mar 2006, at 22:35, Ben Lavender wrote:
>> Hi all,
>> I've come across a situation where a client needs a change in
>> requirements which would, ideally, require a slight slight breaking
>> out of one class into a base class and two sub classes.  Put shortly,
>> I have an event which is based on due dates right now, but some
>> classes of events are turning up which need to be done based on
>> mileage instead.
> Class::DBI doesn't like data classes to inherit from one another, and I 
> very much doubt that it would like objects to switch from one data class 
> to another after they've been retrieved. I'm sure it could be made to 
> work, but the way cdbi holds closures at class level and its increasing 
> use of plugins make it fairly horrible to debug that kind of code, or it 
> does for me anyway.

Inheritance was fine as of 0.96 before Tony started doing Odd Things With 
Closures. Class::DBI::Frozen::301 may work here.

DBIx::Class' inflate_result method which can be overridden to rebless 
trivially is a better solution, but probably impossible to backport.

> My advice, based on 8ish years of repeatedly trying to bend cdbi out of 
> shape, is don't. Do it the official cdbi way or find another ORM that 
> matches your problem better: there's plenty of choice now.

I've bent CDBI out of shape successfully a fair few times - the notable result 
being the join and prefetch code in Class::DBI::Sweet. Eventually I gave up 
and decided to re-implement from the ground up with direct community 
involvement, native join, prefetch, aggregate and other complex query support 
and a structure designed from the ground up to be overridable as required.

Oh, and DBIx::Class 0.06 will be out shortly with has_many prefetch, HAVING 
support and much-improved docs. Keep an eye on CPAN - I'd announce to the CDBI 
list but I get too much hate mail when I do :)

      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +

More information about the ClassDBI mailing list