I want to select all hotels of a particular category in a particular city and the Class::DBI manpage suggests the following construct: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);
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:$mycat = Categories->retrieve(3); for ( $mycat->hotels(city => 'Timbucktoo') ) { # do something with hotels in Timbucktoo of category 3 }
Can a kind monk point me to the error I am making? Thank you.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.
In reply to Class::DBI: Filtering a many-to-many mapping does not work as advertised on CDBI manpage? by unlinker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |