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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.