[Dbix-class] DBIx::Class - Trying to get column names from a $rs or $row

Matt S Trout dbix-class at trout.me.uk
Wed Nov 12 20:39:48 GMT 2008


On Tue, Oct 14, 2008 at 07:59:44PM +0100, Howe, Tom (IT) wrote:
> Hi, first post here
> 
> I have a question regarding  getting column names from a DBIx ::Class $resultset or $row.
> 
> I have a DBIx::Class resultset which I'll call $rset
> 
> I need to get the column names of the resultset in the correct order.
> 
> I was advised  by a coleague  to use $rset->result_source->columns;
> 
> This have me the column names of the table that was the original source of the resultset which initially worked ok.
> 
> However, now that I am doing some selects on the table the resultset only contains a subset of the table columns
> 
> I tried doing
> 
> my $row = $rset->first;
> %row = $row->get_columns;

my @cols = grep { exists $row{$_} } $rset->result_source->columns;

or, really, if you're supplying a subset of columns, just hang onto the
array you supplied for that.

> my @cols = keys %row;
> 
> But now I dont have them in the correct order.
> 
> Is there anyway to get an (ordered)  list of the column names from the $resultset or the $row

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list