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);
####
$mycat = Categories->retrieve(3);
for ( $mycat->hotels(city => 'Timbucktoo') ) {
# do something with hotels in Timbucktoo of category 3
}
####
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.