[Dbix-class] Lazy Columns via proxy

Ovid publiustemp-dbic at yahoo.com
Mon May 17 13:41:50 GMT 2010


Still working on the "lazy" column problem and I was thinking about:

    DBIx::Class::LazyColumns

And in your code:

    package My::Schema::Result::SomeTable;
    use parent 'DBIx::Class';
 
    __PACKAGE__->load_components(
      "LazyColumns",
      "PK",
      "Core",
    );

    __PACKAGE__->table("sometable");
    __PACKAGE__->add_columns(qw/id this that/);
    __PACKAGE__->set_primary_key('id');
    # I think this would have to be done after the primary key
    __PACKAGE__->add_lazy_columns(qw/more columns/);

(I *know* that doing this on a class-based instead of an instance-based basis is problematic, but we have technical details which mitigate this problem for us)

My strategy for implementing this to internally create:

    package My::Schema::Result::SomeTable::Lazy;
    use Modern::Perl;
    use parent 'DBIx::Class';
 
    __PACKAGE__->load_components(
      "PK",
      "Core",
    );

    __PACKAGE__->table("sometable");
    __PACKAGE__->add_columns(qw/id more columns/);
    __PACKAGE__->set_primary_key('id');

And add this relationship to the original table:

    __PACKAGE__->has_one(
      lazy_columns => 'My::Schema::Result::SomeTable::Lazy',
      undef => { proxy => \@lazy_columns },
    );

I think I'll have to override new() or insert() to pull off the lazy columns from the arguments and create them via the new ::Lazy class to make this backwards-compatible.

Does this strategy seem workable?

Cheers,
Ovid
--
Buy the book         - http://www.oreilly.com/catalog/perlhks/
Tech blog            - http://blogs.perl.org/users/ovid/
Twitter              - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6




More information about the DBIx-Class mailing list