Based on my reading of the mailing list archives I have gathered that what I initially was attempting is just not possible, that is to have a many-to-many map_record be used as half of another many-to-many (if I am wrong about that reading please correct). I can live with that, as long as I can figure out some other way to represent it, but I have struggled most of today to get this to work, so am turning to the list to correct my confusion. Thanks for your help, sorry for the length of this message.
I have 5 tables: companies company_branches user_company_branch_map user_company_map users Whose names are mostly arbitrary, and based on what I thought was going to work, so can be changed (and probably will be). 'companies' and 'users' are simple domain tables. 'company_branches' stores a one-to-many of companies to their branches. 'user_company_map' stores what I thought would originally be a many-to-many between the users and the companies they have access to. 'user_company_branch_map' would then store a many-to-many between the company+user that has access to a specific branch of said company. After the reading I did I attempted to break this up into one-to-many relationships where possible (I also attempted a bunch of other things, none of which worked). After instantiating directly the Company::User (and loading it), I attempt to use a method that I thought would be available, $company_user->add_restricted_branches( { branch_code => $user_branch_row->{mb_code} } ); and I end up with: Can't locate object method "add_restricted_branches" via package "M::Company::User" Methods for the following relationships and foreign keys were deferred and then never actually created in the class M::Company::User. TYPE NAME ---- ---- Relationship restricted_branches blah, blah (which I can provide if it would help). The closest I got with using the many-to-many relationships was a FK constraint failure from an empty primary key which should have been determined from a parent object and not been empty. I will paste the code as it stands at the moment below, any pointers would be helpful. It can be assumed that all classes inherit from a base class that handles the normal Rose::DB stuff, and that all classes have a corresponding manager class that does its normal Rose stuff, specifically calling 'make_manager_methods', this stuff has been clipped to keep this as short as possible, it can be provided if necessary. Thanks for the insights, http://danconia.org -- Begin Code -- ############################################################################# package M::User; __PACKAGE__->meta->setup( table => 'users', columns => [ username => { }, ], primary_key_columns => 'username', relationships => [ companies => { type => 'one to many', class => 'M::User::Company', }, ], ); ############################################################################# package M::Company; use M::Company::Branch; use M::Company::User; __PACKAGE__->meta->setup( table => 'companies', columns => [ company_code => { }, ], primary_key_columns => [ 'company_code' ], relationships => [ branches => { type => 'one to many', class => 'M::Company::Branch', key_columns => { company_code => 'company_code' }, }, users => { type => 'one to many', class => 'M::Company::User', key_columns => { company_code => 'company_code' }, }, ], ); ############################################################################# package M::Company::Branch; __PACKAGE__->meta->setup( table => 'company_branches', columns => [ company_code => { }, branch_code => { }, ], primary_key_columns => [ qw( company_code branch_code ) ], foreign_keys => [ company => { class => 'M::Company', key_columns => { company_code => 'company_code', }, }, ], relationships => [ company_branch_users => { type => 'many to one', class => 'M::Company::User::Branch', key_columns => { company_code => 'company_code', branch_code => 'branch_code', }, }, ], ); ############################################################################# package M::Company::User; use M::User; use M::Company; use M::Company::User::Branch; __PACKAGE__->meta->setup( table => 'user_company_map', columns => [ username => { }, company_code => { }, restricted => { }, ], primary_key_columns => [ qw( username company_code ) ], foreign_keys => [ user => { class => 'M::User', key_columns => { username => 'username', }, }, company => { class => 'M::Company', key_columns => { company_code => 'company_code', }, }, ], relationships => [ restricted_branches => { type => 'one to many', class => 'M::Company::User::Branch', }, ], ); ############################################################################# package M::Company::User::Branch; use M::Company::User; use M::Company::Branch; __PACKAGE__->meta->setup( table => 'user_company_branch_map', columns => [ username => { }, company_code => { }, branch_code => { }, ], primary_key_columns => [ qw( username company_code branch_code ) ], foreign_keys => [ company_user => { class => 'M::Company::User', key_columns => { username => 'username', company_code => 'company_code', }, }, company_branch => { class => 'M::Company::Branch', key_columns => { company_code => 'company_code', branch_code => 'branch_code', }, }, ], ); ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object