Re: has_many and '... needs a valid column ...'

[prev] [thread] [next] [Date index for 2005/07/06]

From: Fred Moyer
Subject: Re: has_many and '... needs a valid column ...'
Date: 06:38 on 06 Jul 2005
> I've read about 50 msgs from the archives, found by searching for 'needs a valid
> column', but nothing seems to fit the bill.

I've only seen this error when the relationships between the classes
weren't setup correctly.  I haven't run into that error because of a
lack of data, in that case the database always throws a constraint
error.  Here's how I use has_many:

package My::Model::Chicken;

__PACKAGE__->set_up_table('chicken');  # primary key is chicken_id
__PACKAGE__->has_many( eggs => 'My::Model::Chicken::Egg' );

sub cluck {
  print "Try using Carp qw(cluck), I'm a chicken not an error class :|";
}

package My::Model::Chicken::Egg;

__PACKAGE__->set_up_table('egg'); # foreign key exists for chicken_id
__PACKAGE__->has_a( chicken_id => 'My::Model::Chicken' );
# my chicken table has chicken_id as the primary key

sub over_easy {
  my $egg = shift;
  print "Hey who you callin' easy?";
}

my $chicken = My::Model::Chicken->create();
my @eggs = $chicken->eggs();

foreach my $egg (@eggs) {
  croak("This egg is rotten!")
    unless (ref $egg eq 'My::Model::Chicken::Egg');
}

> How do I get out of what seems like a chicken-and-egg situation?

As demonstrated here, the chicken must clearly come first :)

has_many and '... needs a valid column ...'
Ron Savage 06:20 on 06 Jul 2005

Re: has_many and '... needs a valid column ...'
Fred Moyer 06:38 on 06 Jul 2005

Re: has_many and '... needs a valid column ...'
Tony Bowden 07:22 on 06 Jul 2005

Generated at 16:35 on 28 Jul 2005 by mariachi v0.52