I think the trouble you're having is your relationships are a bit squirrelly. The docs on many_to_many have in the past contained either not enough info or some misleading info. I had trouble with this spot too. Hence-
I have also tried various methods that refer directly to the "map_user_role" relation that is defined in the schemata.
-isn't working the way you'd like and deserve to see. So, this one-
__PACKAGE__->has_many(map_user_role => 'CTIweb::Schema::DB::UserRoles' +, 'user_id'); __PACKAGE__->many_to_many(roles => 'map_user_role', 'role');
-should be (I think, I'm not testing it, just eyeballing it and I changed your "map_user_role" to a straight "user_roles" which is just a personal preference.)-
# User __PACKAGE__->many_to_many( roles => "user_roles", "role_id" ); __PACKAGE__->has_many( "user_roles", "CTIweb::Schema::DB::UserRoles", { "foreign.user_id" => "self.id" }, )
And then-
# Role __PACKAGE__->has_many(map_user_role => 'CTIweb::Schema::DB::UserRoles' +, 'role_id'); __PACKAGE__->has_many(map_acl_role => 'CTIweb::Schema::DB::AclRoles', +'role_id'); # I'm not dealing with this one below # ------------ becomes ----------- __PACKAGE__->has_many( "user_roles", "CTIweb::Schema::DB::UserRoles", { "foreign.role_id" => "self.id" }, ); __PACKAGE__->many_to_many(users => 'user_roles', 'user_id');
Your UserRoles belongs_to stuff is right.
Give that a whirl and the "it just works" stuff should just start working. If it doesn't, please post an SQL schema dump (on your scratchpad) if you can so I can autogenerate stuff and test it for real instead of eyeballing it. :)
I know learning DBIC can be a demoralizing drag but it can seriously pay off later after you get through the "why is this so difficult?" part.
In reply to Re: Problems with DBIx::Class and SQL JOIN's
by Your Mother
in thread Problems with DBIx::Class and SQL JOIN's
by Tommy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |