[Catalyst] Problem with column in DBI
Tomas Doran
bobtfish at bobtfish.net
Wed May 20 10:09:05 GMT 2009
Naylor Garcia wrote:
> I need to make a select in database of the a specific column, but the
> result is a array. How I do to get a specific column?
I think that you meant to post to the DBIC list.
> my $change_color = [$c->model('database::dominio')->search(
> { id_domain => 21240, name => { like => 'naylor garcia' } }
> )];
# N.B. UNTESTED
my $column_name = 'name';
my $rs = $c->model('database::dominio')->search(
{ id_domain => 21240, name => { like => 'naylor garcia' } },
{ columns => [ $column_name ] }, # only get one column from the DB
);
# Inflate rows to hashrefs
$rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
my $change_color = [ map { $_->{$column_name } $rs->all ];
This should all be buried in a method on your ResultSet objects really -
if you're putting logic like this in your Catalyst controllers than
you're doing it wrong.
Cheers
t0m
More information about the Catalyst
mailing list