In the classes you have written, you are using the same name for the many_to_many method from ("group") in User.pm as you have used in method between UserGroup to Group.

__PACKAGE__->many_to_many(group => 'usergroups', 'group');

I have seen this cause problems in my hands when using it for User Role relationships (Authorization::Role and ACL).. I would recommend avoiding reusing the relationship accessor names.


On 11/30/10 8:02 AM, linuxsupport wrote:
Hi,

I am new to Catalyst and DBIx::Class, trying to use many_to_many relationship.

I have 3 tables, users, user_groups, and group, table structure and relationship are setup as follows.

User.pm

__PACKAGE__->add_columns(
  "id",
  { data_type => "integer", is_nullable => 0 },
  "username",
  { data_type => "text", is_nullable => 1 },
  "password",
  { data_type => "text", is_nullable => 1 },
  "email_address",
  { data_type => "text", is_nullable => 1 },
  "first_name",
  { data_type => "text", is_nullable => 1 },
  "last_name",
  { data_type => "text", is_nullable => 1 },
  "active",
  { data_type => "integer", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");

__PACKAGE__->has_many("usergroups", "Example::Schema::Result::UserGroup",{ "foreign.user_id" => "self.id <http://self.id>" },);
__PACKAGE__->many_to_many(group => 'usergroups', 'group');

UserGroup.pm

__PACKAGE__->add_columns(
  "user_id",
  { data_type => "integer", is_nullable => 0 },
  "group_id",
  { data_type => "integer", default_value => 0, is_nullable => 0 },
);
__PACKAGE__->set_primary_key("user_id", "group_id");

__PACKAGE__->belongs_to("user", "Example::Schema::Result::User", { id => "user_id" },{ join_type => "LEFT" },); __PACKAGE__->belongs_to("group", "Example::Schema::Result::Group", { id => "group_id" },{ join_type => "LEFT" },);

Group.pm

__PACKAGE__->add_columns(
  "id",
  { data_type => "integer", is_nullable => 0 },
  "group",
  { data_type => "text", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");

__PACKAGE__->has_many("usergroup","Example::Schema::Result::UserGroup",{ "foreign.group_id" => "self.id <http://self.id>" },);

Can anyone tell me how I can retrieve all the users who are member of a group called 'manager'?

Thanks


--
Kutbuddin Doctor, PhD
Bioinformatics Shared Resource,
Sanford-Burnham Medical Research Institute
http://www.sanfordburnham.org/

_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to