[Dbix-class] coercing Result objects

Aaron Trevena aaron.trevena at gmail.com
Mon Nov 26 09:29:51 GMT 2012

On 13 November 2012 14:55, Dave Howorth <dhoworth at mrc-lmb.cam.ac.uk> wrote:
> I have an odd setup of Result classes, because I live with an odd
> database. There are a bunch of tables that are all very similar but all
> a bit different. So I have a bunch of Result classes that directly
> reflect each individual table with all its quirks. And I also have an
> overarching virtual Result class that makes a view by taking a UNION of
> all the tables and extracting the common fields. It all works.
> Sometimes, I retrieve a record from one of the tables and need to
> convert it to the general form, or I retrieve a record via the
> overarching class and need to get the specific form. So the Result
> classes have methods that perform this transformation. At the moment,
> they do it by doing ->find($id) on a resultset of the appropriate class.
> But this isn't very nice because it hits the database again to retrieve
> the same data just to wrap it in a different object. And that can be a
> performance problem, quite apart from being ugly.
> So is there any way to tell DBIC to rewrap the data in different object
> clothes without hitting the database each time?

This sounds like the problem that this recipe in the cookbook tries to
solve : http://search.cpan.org/~getty/DBIx-Class-0.08204/lib/DBIx/Class/Manual/Cookbook.pod#Dynamic_Sub-classing_DBIx::Class_proxy_classes

might also be worth a look.

This is something I'm looking at myself (search results spanning
tables via a big union ( DBIx::Class::Helpers has a helper for that
too btw)

I might not fully understand what you're doing, hopefully that's some help tho.



Aaron J Trevena, BSc Hons
LAMP System Integration, Development and Consulting

More information about the DBIx-Class mailing list