On 1/9/06, Scott Karns <[EMAIL PROTECTED]> wrote: > OK, that certainly works. Perhaps not exactly as I had expected, but it works. > I guess I was approaching it as though the query was a multi-table inner join > with the iterator returning a single row of the query result containing all > columns of all tables involved.
That's not very useful if you want to iterate over all School::CourseSection objects but *don't* necessarily want to iterate over all sub-objects. If it was done the way you describe, you'd be required to manually iterate over every single sub-object even if you weren't interested in all of those sub-objects for each "main" (School::CourseSection) object. > I guess I need to look at approaching the listing of instructors and the > classes they teach from a different angle, as sorting that list by instructor > name should be possible (and easy!) If you want a list of "instructors and the classes they teach, sorted by instructor name" with your current table structure, then try something like this: package School::Person; use School::ClassInstructor; ... # Add a relationship between a person and School::Person->meta->relationships ( course_sections => { type => 'many to many', map_class => 'School::ClassInstructor', # Note that these are probably optional since the # class_instructor table has just two well-defined # foreign keys, so it's obvious what maps to what. map_from => 'instructor', map_to => 'the_class', }, ); package School::Person::Manager; use strict; use School::Person; # don't forget to use() the object_class! use base 'Rose::DB::Object::Manager'; sub object_class { 'School::Person' } __PACKAGE__->make_manager_methods('persons'); Now the loop: $iterator = School::Person::Manager->get_persons_iterator( require_objects => [ 'course_sections.course', 'course_sections.room' ], sort_by => [ qw(lname fname) ]); while(my $instructor = $iterator ->next) { foreach my $cs ($instructor->course_sections) { print $instructor->fname, ' ', $instructor->lname, ' teaches ', $cs->course->short_cname, ', section ', $cs->sect_num, ' in ', $cs->room->short_rmname, ".\n"; } } Note that the sort_by arguments no longer have to be qualified since the "person" table to which they belong is now the primary table. Also note that you could remove all of the "require_objects" args in the get_persons_iterator() call and leave the loop code as-is. The difference would be that many more queries would be run, of course. With the require_objects arguments as shown, all information should be retrieved in a single query. But semantically, that's an optimization from the perspective of the loop code. -John ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_idv37&alloc_id865&op=click _______________________________________________ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object