[Dbix-class] fetching a column value directly

Hailin Hu i at h2l.name
Mon Nov 4 07:27:07 GMT 2013


1. Define column host as unique in your Result pm, then you can use
$rs->find({ host => $host })->addr;
2. Use method first()
$hostAdd = $rs->search({host => $host})->get_column('addr')->first;

On Mon, Nov 4, 2013 at 2:29 PM, Rajeev Prasad <rp.neuli at yahoo.com> wrote:
>
>
> hello,
>
> I have this "host" table, which has all unique records. So i want to get a specific column value for a specific host. i am doing below, but i think it is not efficient. is there a better way?
>
> my $hostAdd_rs = $schema->resultset('Host')->search({host=>$host},{select=>[qw/addr/]});
> while (my $rec = $hostAdd_rs-next() ) {
>     $hostAdd = $rec->get_column('addr');
> }
>
>
> can we not do it in a single line command? without any while loop?
>
> i tried, but getting various errors.
>
> ty.
> Rajeev
>
>
> _______________________________________________
> 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.scsys.co.uk



More information about the DBIx-Class mailing list