[Dbix-class] Many to many relationship searching
jakac
jakac at iprom.si
Mon Jun 23 08:32:32 BST 2008
Hello,
I am developing application using Catalyst & Postgres and I have a =
simple many to many
relationship that includes following three tables:
- categories (category_id primary key, category_name, users_id, ......)
- articles (article_id primary key, title, content.......)
- categories_articles_rel (rel_id primary key, category_id, article_id)
My schema includes:
# CATEGORIES
__PACKAGE__->has_many( "categories_articles_rel", =
"MyDB::CategoriesArticlesRel", { "foreign.category_id" =3D> =
"self.category_id" }, );
# ARTICLES
__PACKAGE__->has_many( "categories_articles_rel", =
"MyDB::CategoriesArticlesRel", { "foreign.article_id" =3D> =
"self.article_id" }, );
# CATEGORIES_ARTICLES_REL
__PACKAGE__->belongs_to( "category_id", "MyDB::Categories", { =
category_id =3D> "category_id" },);
__PACKAGE__->belongs_to( "article_id", "MyDB::Articles", { recipients_id =
=3D> "recipients_id" }, );
Now I want to get a list of all articles that are in categories that are =
owned by
certain user and order them by some field... Using the plain SQL I would =
normally write:
select a.* from articles a, categories c, categories_articles_rel rel
where
a.article_id =3D rel.article_id
and
c.category_id =3D rel.category_id
and
c.user_id =3D '$someuser'
order by a.title;
(if I want to order by title)
So now my question is - how to do this using DBIx::Class?
Thank you!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20080623/6ef=
9a3d3/attachment-0001.htm
More information about the DBIx-Class
mailing list