Re: Class::DBI::Loader and accessors

[prev] [thread] [next] [Date index for 2005/03/16]

From: Kingsley Kerce
Subject: Re: Class::DBI::Loader and accessors
Date: 17:51 on 16 Mar 2005
Kingsley Kerce writes:
 > Perrin Harkins writes:
 >  > Isn't this what the "additional_base_classes" parameter in Loader is
 >  > for?
 > 
 > Well, yeah, if you're running CDBIL >= 0.06, unlike me. :)
 > I'll upgrade.  Thanks for the reality check, Perrin.

Using Class::DBI::Loader 0.17 and the additional*_classes params, I've
managed to eliminate looping/eval'ing over all my CDBI table classes
in order to include my base class My::DBI and the plugin class
Class::DBI::Plugin::RetrieveAll.

But I can't find a way to move some add_relationship_type() and
columns() invocations -- which must be done for every table class --
into my base class.  Appended below is my app-initialization code,
before and after using CDBIL 0.17.

Looking at the second chunk of code below, is there a way to eliminate
looping over the table classes, and move the add_relationship_type()
and columns() calls into my base class, such that those calls will
occur during the CDBIL phase?

Thanks,
Kings


#------------------------------------------------------------------------------
#-- OLD METHOD, USING Class::DBI::Loader 0.03 ---------------------------------
#------------------------------------------------------------------------------

  my $loader = Class::DBI::Loader->new(
    dsn => $data_source,
    user => $db_user,
    password => $db_pass,
    namespace => "My",
    options => { 
      # ...
    }
  ));

  # We do not use triggers in this application.  In particular, we want
  # PostgreSQL to cascade deletions rather than having Class::DBI do it.
  eval "package Class::DBI::Relationship::HasMany::NoCascadeDelete;

        use base 'Class::DBI::Relationship::HasMany';

        sub triggers { return () }
       ";
  confess $@ if $@;

  foreach my $class ($loader->classes) {
    eval "package $class;

          use base 'My::DBI';

          use Class::DBI::Plugin::RetrieveAll;
          __PACKAGE__->add_relationship_type(has_many => 'Class::DBI::Relationship::HasMany::NoCascadeDelete');
          if ('$class' =~ /Type\$/) {
            # May as well pull in all columns of db tables named %_type 
            __PACKAGE__->columns(Essential => __PACKAGE__->columns);
          }
    ";
    confess $@ if $@;
  }

#------------------------------------------------------------------------------
#-- IMPROVED METHOD, USING Class::DBI::Loader 0.17 ----------------------------
#------------------------------------------------------------------------------

  my $loader(Class::DBI::Loader->new(
    dsn => $data_source,
    user => $db_user,
    password => $db_pass,
    namespace => "My",
    additional_classes => qw/Class::DBI::Plugin::RetrieveAll/,
    additional_base_classes => qw/My::DBI/,
    options => { 
      # ...
    }
  ));

  # We do not use triggers in this application.  In particular, we want
  # PostgreSQL to cascade deletions rather than having Class::DBI do it.
  eval "package Class::DBI::Relationship::HasMany::NoCascadeDelete;

        use base 'Class::DBI::Relationship::HasMany';

        sub triggers { return () }
       ";
  confess $@ if $@;

  foreach my $class ($loader->classes) {
    $class->add_relationship_type(has_many => 'Class::DBI::Relationship::HasMany::NoCascadeDelete');
    if ($class =~ /Type$/) {
      # May as well pull in all columns of db tables named %_type 
      $class->columns(Essential => $class->columns);
    }
  }

#------------------------------------------------------------------------------

(message missing)

Class::DBI::Loader and accessors
Sean Davis 21:10 on 15 Mar 2005

Re: Class::DBI::Loader and accessors
Kingsley Kerce 21:29 on 15 Mar 2005

Re: Class::DBI::Loader and accessors
Perrin Harkins 21:51 on 15 Mar 2005

Re: Class::DBI::Loader and accessors
Kingsley Kerce 22:28 on 15 Mar 2005

Re: Class::DBI::Loader and accessors
Kingsley Kerce 17:51 on 16 Mar 2005

Re: Class::DBI::Loader and accessors
Perrin Harkins 19:22 on 17 Mar 2005

RE: Class::DBI::Loader and accessors
Zhuang Li 18:48 on 17 Mar 2005

RE: Class::DBI::Loader and accessors
Kingsley Kerce 19:07 on 17 Mar 2005

RE: Class::DBI::Loader and accessors
Zhuang Li 20:02 on 17 Mar 2005

RE: Class::DBI::Loader and accessors
Kingsley Kerce 21:02 on 17 Mar 2005

Re: Class::DBI::Loader and accessors
Tony Bowden 23:16 on 17 Mar 2005

RE: Class::DBI::Loader and accessors
Zhuang Li 21:43 on 17 Mar 2005

Can't call id() as a class method
Tom Gazzini 22:44 on 17 Mar 2005

Re: Can't call id() as a class method
Perrin Harkins 22:52 on 17 Mar 2005

Re: Can't call id() as a class method
Tony Bowden 23:15 on 17 Mar 2005

RE: Class::DBI::Loader and accessors
Zhuang Li 21:54 on 23 Mar 2005

Re: Class::DBI::Loader and accessors
Tim Bunce 22:26 on 23 Mar 2005

Re: Class::DBI::Loader and accessors
Tony Bowden 23:00 on 23 Mar 2005

Re: Class::DBI::Loader and accessors
Tony Bowden 23:34 on 23 Mar 2005

RE: Class::DBI::Loader and accessors
Zhuang Li 23:07 on 23 Mar 2005

RE: Class::DBI::Loader and accessors
Zhuang Li 23:50 on 23 Mar 2005

RE: Class::DBI::Loader and accessors
Peter Speltz 00:04 on 24 Mar 2005

Generated at 15:09 on 27 Mar 2005 by mariachi v0.52