FAQ
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" },);
__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" },);

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

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20101130/7f1a05f6/attachment.htm

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 5 | next ›
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedNov 30, '10 at 4:02p
activeNov 30, '10 at 5:57p
posts5
users4
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2022 Grokbase