[Catalyst] DBIx::Class many_to_many relationship
linuxsupport
lin.support at gmail.com
Tue Nov 30 16:02:27 GMT 2010
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 =3D> "integer", is_nullable =3D> 0 },
"username",
{ data_type =3D> "text", is_nullable =3D> 1 },
"password",
{ data_type =3D> "text", is_nullable =3D> 1 },
"email_address",
{ data_type =3D> "text", is_nullable =3D> 1 },
"first_name",
{ data_type =3D> "text", is_nullable =3D> 1 },
"last_name",
{ data_type =3D> "text", is_nullable =3D> 1 },
"active",
{ data_type =3D> "integer", is_nullable =3D> 1 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->has_many("usergroups", "Example::Schema::Result::UserGroup",{
"foreign.user_id" =3D> "self.id" },);
__PACKAGE__->many_to_many(group =3D> 'usergroups', 'group');
UserGroup.pm
__PACKAGE__->add_columns(
"user_id",
{ data_type =3D> "integer", is_nullable =3D> 0 },
"group_id",
{ data_type =3D> "integer", default_value =3D> 0, is_nullable =3D> 0 },
);
__PACKAGE__->set_primary_key("user_id", "group_id");
__PACKAGE__->belongs_to("user", "Example::Schema::Result::User", { id =3D>
"user_id" },{ join_type =3D> "LEFT" },);
__PACKAGE__->belongs_to("group", "Example::Schema::Result::Group", { id =3D>
"group_id" },{ join_type =3D> "LEFT" },);
Group.pm
__PACKAGE__->add_columns(
"id",
{ data_type =3D> "integer", is_nullable =3D> 0 },
"group",
{ data_type =3D> "text", is_nullable =3D> 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->has_many("usergroup","Example::Schema::Result::UserGroup",{
"foreign.group_id" =3D> "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/7f1a0=
5f6/attachment.htm
More information about the Catalyst
mailing list