__PACKAGE__->load_components(qw/AccessorGroup/);
__PACKAGE__->mk_group_accessors('simple' =>
- qw/_columns _primaries name resultset_class result_class schema from/);
+ qw/_ordered_columns _columns _primaries name resultset_class result_class schema from/);
=head1 NAME
$class = ref $class if ref $class;
my $new = bless({ %{$attrs || {}} }, $class);
$new->{resultset_class} ||= 'DBIx::Class::ResultSet';
+ $new->{_ordered_columns} ||= [];
$new->{_columns} ||= {};
$new->{name} ||= "!!NAME NOT SET!!";
return $new;
sub add_columns {
my ($self, @cols) = @_;
+ $self->_ordered_columns( \@cols )
+ if !$self->_ordered_columns;
+ push @{ $self->_ordered_columns }, @cols;
while (my $col = shift @cols) {
$self->_columns->{$col} = (ref $cols[0] ? shift : {});
}
return keys %{shift->_columns};
}
+=head2 ordered_columns
+
+ my @column_names = $obj->ordered_columns;
+
+Like columns(), but returns column names using the order in which they were
+originally supplied to add_columns().
+
+=cut
+
+sub ordered_columns {
+ return @{shift->{_ordered_columns}||[]};
+}
+
=head2 set_primary_key(@cols)
Defines one or more columns as primary key for this source. Should be
sub run_tests {
-plan tests => 33;
+plan tests => 34;
my @art = DBICTest->class("Artist")->search({ }, { order_by => 'name DESC'});
$cd->discard_changes;
+# check whether ResultSource->ordered_columns returns columns in order originally supplied
+my @cd = DBICTest->class("CD")->find(1)->result_source->ordered_columns;
+
+is_deeply( \@cd, [qw/cdid artist title year/], 'ordered_columns');
+
$cd = DBICTest->class("CD")->search({ title => 'Spoonful of bees' }, { cols => ['title'] })->next;
is($cd->title, 'Spoonful of bees', 'subset of columns returned correctly');