[Dbix-class] Best possible way to retrieve data using relationship
linuxsupport
lin.support at gmail.com
Tue Dec 28 11:02:46 GMT 2010
Hi,
I am trying to find best way to fetch data from multiple table using
DBIx::Class relationship.
I have 3 tables as follows.
Articles ( id, title, sort_text) primary key =3D> id
ArticleAuthor (article_id, author_id) primary key =3D> (article_id, author_=
id)
Author (id, author_name) primary key =3D> id
Relationship.
Article.pm
has_many(article_author =3D> "Article::Author", "article_id")
ArticleAuthor.pm
has_many(author =3D> "Author", "id")
I want to get title and sort_text from articles table and author_name form
author table for a given id.
I tried this
$schema->resultset('Article)->search(
{
id =3D> '1'
},
{ join =3D> { article_author =3D> author }
prefetch =3D> { article_author =3D> author }
}
);
This returns me all the table filelds from all three table, I tried to put
something columns =3D> [qw/ title sort_text author_name/] but did not work.
I want to know if above is correct way to use relationship? or is there a
better way of doing the same?
And how I can get only required columns.
Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20101228/d22=
a9191/attachment.htm
More information about the DBIx-Class
mailing list