I agree with
Ovid -- this is a very strange schema design. However, assuming you did it this way just to see if Class::DBI can handle something strange, there is a much more elegant way to deal with this. You are trying to use a linking table here, which is supported by Class::DBI using has_many (see the style refs example in the docs) but it's confusing. Another approach is to write the query directly in the names class, like this:
package Name;
...
__PACKAGE__->set_sql(by_person => q/
SELECT n.name
FROM name n, person_name pn
WHERE (n.name_id = pn.firstname
OR n.name_id = pn.lastname)
AND pn.person = ?
/);
package Person;
...
sub names {
my $self = shift;
Name->search_by_person($self);
}
it seems like Class::DBI forces you to name references without any ending '_id' if you want some nifty named methods in your classes?
No, you can name things whatever you want. Look at the section on changing accessor names in the docs.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.