arc_of_descent has asked for the wisdom of the Perl Monks concerning the following question:
Hello Dear Monks
I'm having some trouble setting up a has_many relationship between 2 entities - a page entity and a column entity. The relationship I'm tring to use in my code is 'a page has many columns'.
If I structure the tables in the following way, I'm facing no problems.
|
|
I set up all the DBI modules, etc... and in Page.pm I add a line:
__PACKAGE__->has_many(cols => 'Column');
Now I can get all columns of a page with the following code:
$columns = Page->retrieve(1)->cols;
Now good database design, has taught me that when one has a 1:N relationship, one should construct a new table to hold that relationship.
So, the foll structure:
|
|
|
So now how do I code the relationships in my Class::DBI modules
which would enable me to get all the columns of a page in the same was as above.
i.e.
$columns = Page->retrieve(1)->cols;
Thankz in advance for all suggestions and help and compliments of the season to all of you!
update:
Changed the 'columns' method to 'cols' since Class::DBI already has a 'columns' method
- Thanks to PodMaster
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Class::DBI has_many
by kal (Hermit) on Dec 29, 2003 at 13:32 UTC | |
Re: Class::DBI has_many
by PodMaster (Abbot) on Dec 29, 2003 at 13:33 UTC | |
by arc_of_descent (Hermit) on Dec 29, 2003 at 13:48 UTC | |
by PodMaster (Abbot) on Dec 29, 2003 at 13:57 UTC | |
by arc_of_descent (Hermit) on Dec 29, 2003 at 14:07 UTC | |
by jeffa (Bishop) on Dec 29, 2003 at 14:20 UTC | |
| |
by PodMaster (Abbot) on Dec 29, 2003 at 14:32 UTC | |
by boo_radley (Parson) on Dec 29, 2003 at 15:34 UTC | |
Re: Class::DBI has_many
by hardburn (Abbot) on Dec 29, 2003 at 14:38 UTC | |
Re: Class::DBI has_many
by boo_radley (Parson) on Dec 29, 2003 at 15:49 UTC | |
Re: Class::DBI has_many
by CountZero (Bishop) on Dec 29, 2003 at 16:29 UTC | |
Re: Class::DBI has_many
by arc_of_descent (Hermit) on Dec 30, 2003 at 10:58 UTC |