return $class->next::method(map lc, @cols);
}
+sub add_columns {
+ my ($class, @cols) = @_;
+ $class->table_instance->add_columns(map lc, @cols);
+ $class->_mk_column_accessors(@cols);
+}
+
sub has_a {
my ($class, $col, @rest) = @_;
$class->next::method(lc($col), @rest);
$class->set_primary_key($cols[0]);
}
unless (exists $class->_column_groups->{'Essential'}) {
- #$class->_register_column_group('Essential' => $cols[0]);
$groups->{'Essential'}{$cols[0]} = {};
- #$groups->{'Essential'}{$_} ||= {} for keys %{ $class->_primaries || {} };
}
}
$groups->{$group}{$_} ||= {} for @cols;
- #if ($group eq 'Essential') {
- # $groups->{$group}{$_} ||= {} for keys %{ $class->_primaries || {} };
- #}
$class->_column_groups($groups);
}
-sub all_columns { return keys %{$_[0]->_columns}; }
+sub all_columns { return shift->table_instance->columns; }
sub primary_column {
my ($class) = @_;
sub set_sql {
my ($class, $name, $sql) = @_;
- my $table = $class->_table_name;
- #$sql =~ s/__TABLE__/$table/;
no strict 'refs';
*{"${class}::sql_${name}"} =
sub {
sub transform_sql {
my ($class, $sql, @args) = @_;
- my $table = $class->_table_name;
my $attrs = { };
foreach my $key (@{$class->_transform_sql_handler_order}) {
my $h = $class->_transform_sql_handlers->{$key};
$class = ref $class if ref $class;
$attrs = { %{ $attrs || {} } };
my %seen;
- $attrs->{cols} ||= [ map { "me.$_" } $source->columns ];
+ $attrs->{cols} ||= [ map { "me.$_" } $source->result_class->_select_columns ];
$attrs->{from} ||= [ { 'me' => $source->name } ];
if ($attrs->{join}) {
foreach my $j (ref $attrs->{join} eq 'ARRAY'
unless $seen{$pre};
push(@{$attrs->{cols}},
map { "$pre.$_" }
- $source->result_class->_relationships->{$pre}->{class}->table->columns);
+ $source->result_class->_relationships->{$pre}->{class}->columns);
}
my $new = {
source => $source,
while (my ($comp, $comp_class) = each %reg) {
my $target_class = "${target}::${comp}";
$class->inject_base($target_class, $comp_class, $conn_class);
- my $table = $comp_class->table->new({ %{$comp_class->table} });
- $table->result_class($target_class);
- $target_class->table($table);
@map{$comp, $comp_class} = ($target_class, $target_class);
}
{
sub new {
my ($class, $attrs) = @_;
$class = ref $class if ref $class;
- my $new = bless($attrs || {}, $class);
+ my $new = bless({ %{$attrs || {}} }, $class);
$new->{resultset_class} ||= 'DBIx::Class::ResultSet';
$new->{_columns} ||= {};
$new->{name} ||= "!!NAME NOT SET!!";
__PACKAGE__->mk_classdata('_resultset_class' => 'DBIx::Class::ResultSet');
-sub iterator_class { shift->table->resultset_class(@_) }
-sub resultset_class { shift->table->resultset_class(@_) }
-sub _table_name { shift->table->name }
+sub iterator_class { shift->table_instance->resultset_class(@_) }
+sub resultset_class { shift->table_instance->resultset_class(@_) }
+sub _table_name { shift->table_instance->name }
=head1 NAME
sub add_columns {
my ($class, @cols) = @_;
- $class->table->add_columns(@cols);
+ $class->table_instance->add_columns(@cols);
$class->_mk_column_accessors(@cols);
}
sub resultset_instance {
my $class = shift;
- $class->table->storage($class->storage);
- $class->next::method($class->table->resultset);
+ my $table = $class->table_instance->new($class->table_instance);
+ $table->storage($class->storage);
+ $table->result_class($class);
+ return $table->resultset;
}
sub _select_columns {
- return shift->table->columns;
+ return shift->table_instance->columns;
}
=head2 table
sub table {
my ($class, $table) = @_;
- die "$class->table called and no table instance set yet" unless $table;
+ return $class->table_instance->name unless $table;
unless (ref $table) {
$table = DBIx::Class::Table->new(
{
result_class => $class,
#storage => $class->storage,
});
+ if ($class->can('table_instance')) {
+ $table->{_columns} = { %{$class->table_instance->{_columns}||{}} };
+ }
}
- $class->mk_classdata('table' => $table);
+ $class->mk_classdata('table_instance' => $table);
}
=head2 find_or_create
sub has_column {
my ($self, $column) = @_;
- return $self->table->has_column($column);
+ return $self->table_instance->has_column($column);
}
=head2 column_info
sub column_info {
my ($self, $column) = @_;
- return $self->table->column_info($column);
+ return $self->table_instance->column_info($column);
}
=head2 columns
=cut
sub columns {
- return shift->table->columns(@_);
+ return shift->table_instance->columns(@_);
}
1;
package A;
@A::ISA = qw(DBIx::Class);
__PACKAGE__->load_components(qw/CDBICompat Core/);
+__PACKAGE__->table('dummy');
__PACKAGE__->columns(Primary => 'id');
package A::B;
@A::B::ISA = 'A';
+__PACKAGE__->table('dummy2');
__PACKAGE__->columns(All => qw(id b1));
package A::C;
@A::C::ISA = 'A';
+__PACKAGE__->table('dummy3');
__PACKAGE__->columns(All => qw(id c1 c2 c3));
package main;
package main;
Actor->iterator_class('Class::DBI::My::Iterator');
-Actor->resultset_instance(Actor->construct_resultset);
{
my @acts = $film->actors->slice(1, 2);