[Catalyst] CDBI Plain not inheriting table and columns

Jonathan Manning jmanning at alisa-jon.net
Tue Aug 2 18:52:38 CEST 2005


Matt S Trout wrote:
> What do you mean "Catalyst can't find the table" ??
> 
> CatalystApp::M::Experiment->retrieve(...) for example should work fine.
> 
> Paste some example code from your Controller classes to explain, please.

I don't have much controller code yet because I can't get the basics to
work. I tried the following:

sub view :Local {
  my ($self, $c) = @_;
  $c->stash->{table} = CatalystApp::M::Experiment->table; # debug
  $c->stash->{item} = CatalystApp::M::Experiment->retrieve(1); ## dies!
  # never gets here...
}

This gives me:
Catalyst error: Caught exception "Can't retrieve unless primary columns
are defined at ./CBrowser/C/Experiments.pm line 110"

And worse, the stash dump shows that the table it is trying to access is
"experiment" not "Experiments" - so it's just using the default
UNIVERSAL::moniker derivation, and not the table I declared in my CDBI
class.

To me, this means it is ignoring both the table and columns I declared
in my CDBI classes.

So, I copy all of the __PACKAGE__->(table|columns|etc.) CDBI calls into
the CatalystApp::M::Experiment class -- it works just fine. (But is an
ugly duplication of code.)

The calls to __PACKAGE__->table and __PACKAGE__->columns in
MyOther::Obj::Experiment are not affecting calls to the
CatalystApp::M::Experiment class. I thought Class::Data::Inheritable
worked around this, but the table and column data are clearly not being
inherited by the subclass.

As the other two replies suggested I could just not inherit from
Catalyst::Model::CDBI::Plain, or use my classes directly. I don't see
any downside to the first approach, and the second only skips
autoloading of Model classes (so I'd have to use my modules manually in
each controller). Is there anything that would be horribly missing if I
ignored CDBI::Plain altogether?

The second example in the POD just doesn't work as advertised. There's
some sort of conflict between CDBI::Plain and normal CDBI modules.
Perhaps the example should be removed unless it can be fixed, or it
works for others. (But I haven't heard from anyone who is successfully
using it in this way.)

~Jonathan




More information about the Catalyst mailing list