[CDBI] Different subclasses for one table / Factory Pattern?

Perrin Harkins perrin at elem.com
Thu Aug 3 17:43:53 BST 2006


On Sun, 2006-07-30 at 21:19 +0200, Stephan Brunner wrote:
> Right now, I have only one table for *all* files, but need to create different 
> File::<something> objects depending on column values (the file name, for 
> example). I want $dir->files() to return a list of objects in the 
> per-file-specific subclass. Is it possible to set this up using Class::DBI? 

You can look at Class::DBI::Relationship::ISA or you can try making
something yourself.  When I needed to do something like this, I made a
class that just had the primary key and the class name for columns and
provided a method which would fetch the correct class of object.  That
does mean extra database fetches.

- Perrin




More information about the ClassDBI mailing list