[CDBI] Normalization

Eamon Daly edaly at nextwavemedia.com
Mon Nov 14 23:38:19 GMT 2005

Okay, so now I'm a touch confused. Suppose I have a table
"foo" with columns "foo_id" (the PK) and "bar_id". Table
"bar" contains columns "bar_id" (the PK) and "bar". How do I
define the relationship between the tables so that these
both work:

my $bar_id = My::Foo->bar_id   # id
my $bar_value = My::Foo->bar   # value

This gets me halfway there:

package My::Bar;

package My::Foo;
__PACKAGE__->has_a(bar_id, 'My::Bar');

and elsewhere:

my $bar_id = My::Foo->bar_id           # id
my $bar_value = My::Foo->bar_id->bar   # value

but like I said, I'd really prefer to just say My::Foo->bar.
I'm sure it's trivial, but I just can't find the right

Eamon Daly

More information about the ClassDBI mailing list