no strict 'refs';
unshift(@{"${target}::ISA"}, grep { $target ne $_ && !$target->isa($_)} @to_inject);
}
+
+ # Yes, this is hack. But it *does* work. Please don't submit tickets about
+ # it on the basis of the comments in Class::C3, the author was on #dbix-class
+ # while I was implementing this.
+
my $table = { Class::C3::_dump_MRO_table };
eval "package $target; import Class::C3;" unless exists $table->{$target};
Class::C3::reinitialize() if defined $table->{$target};
my ($self, @cols) = @_;
$self->_ordered_columns( \@cols )
if !$self->_ordered_columns;
- push @{ $self->_ordered_columns }, @cols;
+ my @added;
+ my $columns = $self->_columns;
while (my $col = shift @cols) {
my $column_info = ref $cols[0] ? shift : {};
# If next entry is { ... } use that for the column info, if not
# use an empty hashref
- $self->_columns->{$col} = $column_info;
+ push(@added, $col) unless exists $columns->{$col};
+
+ $columns->{$col} = $column_info;
}
+ push @{ $self->_ordered_columns }, @added;
}
*add_column = \&add_columns;
=head2 columns
- my @column_names = $obj->columns;
+ my @column_names = $obj->columns;
+
+Returns all column names in the order they were declared to add_columns
=cut
sub columns {
croak "columns() is a read-only accessor, did you mean add_columns()?" if (@_ > 1);
- 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}||[]};
}
});
if ($class->can('result_source_instance')) {
$table->{_columns} = { %{$class->result_source_instance->{_columns}||{}} };
+ $table->{_ordered_columns} =
+ [ @{$class->result_source_instance->{_ordered_columns}||[]} ];
}
}
$class->mk_classdata('result_source_instance' => $table);
$cd->discard_changes;
-# check whether ResultSource->ordered_columns returns columns in order originally supplied
-my @cd = $schema->source("CD")->ordered_columns;
+# check whether ResultSource->columns returns columns in order originally supplied
+my @cd = $schema->source("CD")->columns;
-is_deeply( \@cd, [qw/cdid artist title year/], 'ordered_columns');
+is_deeply( \@cd, [qw/cdid artist title year/], 'column order');
$cd = $schema->resultset("CD")->search({ title => 'Spoonful of bees' }, { cols => ['title'] })->next;
is($cd->title, 'Spoonful of bees', 'subset of columns returned correctly');