[Dbix-class] Re: Best possible way to retrieve data using relationship

linuxsupport lin.support at gmail.com
Thu Dec 30 04:05:57 GMT 2010


Hi,

anyone can direct me on this please?

On Tue, Dec 28, 2010 at 4:32 PM, linuxsupport <lin.support at gmail.com> wrote:

> 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 wor=
k.
>
> 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/20101230/f43=
60f69/attachment.htm


More information about the DBIx-Class mailing list