[Dbix-class] help with dbix::class syntax

jagdish eashwar jagdish.eashwar at gmail.com
Tue Jan 1 15:55:08 GMT 2008


Hi Mark,

Thank you very much. I am not very conversant with DBIx::Class. It took me
quite some time and several trial-and-error attempts to understand and
implement what you suggested. That is why I am a little late in replying.
Thank you again. And a Happy New Year.

Jagdish


On 12/29/07, Mark Smith <smitty at gmail.com> wrote:
>
> > I am writing a small catalyst application for online maintenance of
> leave
> > records at the office. I need to ensure that a dept head is not flooded
> with
> > all the leave applications, but gets only those pertaining to his dept.
> I
> > have a users table and a leave_application table. The first table
> contains
> > the user_id, user_name and dept_id columns, while the second one
> contains
> > the user_id and leave_id columns. I have declared a has_many
> relationship
> > named 'leave_apps' and  a belongs_to relationship named 'usr' between
> the
> > two tables. I am unable to put the following SQL query into DBIx::Class
> > syntax.
> >
> > select l.leave_id from leave_application l,
> >     users u,
> > where u.user_id =3D l.user_id
> > and u.dept_id =3D $dept_id_of_dept_head;
>
> You should be able to do something like this:
>
> my $apps =3D $c->model( 'YourDB::AppClass' )->search(
> {
>    'usr.dept_id' =3D> $dept_id,
> },
> {
>    join =3D> 'usr',
> }
> );
>
> The idea being, you are searching on your app class, but joining it
> with the 'usr' relationship and doing the WHERE class on that
> relationship.
>
> There may be a simpler way to do this, something more natural, but
> this should work.  :-)
>
>
> --
> Mark Smith / xb95
> smitty at gmail.com
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive:
> http://www.grokbase.com/group/dbix-class@lists.rawmode.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20080101/7cb=
b77df/attachment.htm


More information about the DBIx-Class mailing list