Ryan D Johnson wrote:
xyon <[EMAIL PROTECTED]> writes:
I just want to fetch the column names. Below is essentially what I
want to do (but it obviously doesn't work;)):
my @columns = $schema->resultset('data')->columns;
I also have this need.
Is this what you're looking for:
$ $schema->resultset('User')->result_source->columns;
$ARRAY1 = [
'id',
'email',
'username',
'password',
'signup_time',
'activation_code',
'invitations_left'
];
And this isn't what I need. A result set might have columns from joined
tables, or it might not have all of the columns from its base table.
I have the following in my custom ResultSet class, which does what I
need. Perhaps it would be a useful addition to the base ResultSet?
sub columns {
my $self = shift;
my $attr = $self->_resolved_attrs;
return $attr->{as};
}
sub column_info {
my $self = shift;
my $col = shift;
my $attr = $self->_resolved_attrs;
return $attr->{column_info}{$col}
if exists $attr->{column_info} && $attr->{column_info}{$col};
my $source = $self->result_source;
while (my ($left, $right) = $col =~ /^([^.]*)\.(.*)$/) {
$source = $source->related_source($left);
$col = $right;
}
return $source->column_info($col);
}
_______________________________________________
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/[EMAIL PROTECTED]