Venerable Monks
I want to implement a simple many-to-many relation with Class::DBI. Here is a simplified version of my scheme/objects:
package Hotels; __PACKAGE__->table('hotels'); __PACKAGE__->columns(Primary => 'hotel_id'); __PACKAGE__->columns(Others => qw{ name city }); __PACKAGE__->has_many(categories => [HotelCategories => 'category_id'] +); package Categories; __PACKAGE__->table('categories'); __PACKAGE__->columns(Primary => 'category_id'); __PACKAGE__->columns(Others => qw{ name }); __PACKAGE__->has_many(hotels => [HotelCategories => 'hotel_id']); package HotelCategories; __PACKAGE__->table('hotelcategories'); __PACKAGE__->columns(Primary => 'hotelcategory_id'); __PACKAGE__->columns(Others => qw{ hotel_id category_id ); __PACKAGE__->has_a(hotel_id => Hotels); __PACKAGE__->has_a(category_id => Categories);
I want to select all hotels of a particular category in a particular city and the Class::DBI manpage suggests the following construct:
$mycat = Categories->retrieve(3); for ( $mycat->hotels(city => 'Timbucktoo') ) { # do something with hotels in Timbucktoo of category 3 }
Unfortunately this dies with an Error which in effect says: "city is not a column of HotelCategories". Of course I know this! I believe I am mimicking this specific extract from the Class::DBI manpage:
Limiting Music::Artist->has_many(cds => 'Music::CD'); my @cds = $artist->cds(year => 1980); When calling the method created by has_many, you can also supply any additional key/value pairs for restricting the search. The above example will only return the CDs with a year of 1980.
Can a kind monk point me to the error I am making? Thank you.

In reply to Class::DBI: Filtering a many-to-many mapping does not work as advertised on CDBI manpage? by unlinker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.