'0+' => 'count',
fallback => 1;
use Data::Page;
+use Storable;
=head1 NAME
$class->new_result(@_) if ref $class;
my ($source, $attrs) = @_;
#use Data::Dumper; warn Dumper(@_);
- $attrs = { %{ $attrs || {} } };
+ $attrs = Storable::dclone($attrs || {}); # { %{ $attrs || {} } };
my %seen;
my $alias = ($attrs->{alias} ||= 'me');
if (!$attrs->{select}) {
$self->{source}->result_class->throw(
"No such relationship ${rel} in search_related")
unless $rel_obj;
- my $r_class = $self->{source}->result_class->resolve_class($rel_obj->{class});
- my $source = $r_class->result_source;
- $source = bless({ %{$source} }, ref $source || $source);
- $source->storage($self->{source}->storage);
- $source->result_class($r_class);
my $rs = $self->search(undef, { join => $rel });
- #use Data::Dumper; warn Dumper($rs);
- return $source->resultset_class->new(
- $source, { %{$rs->{attrs}},
- alias => $rel,
- select => undef(),
- as => undef() }
+ return $self->{source}->schema->resultset($rel_obj->{class}
+ )->search( undef,
+ { %{$rs->{attrs}},
+ alias => $rel,
+ select => undef(),
+ as => undef() }
)->search(@rest);
}
my $attrs = { %{ $self->{attrs} },
select => { 'count' => '*' },
as => [ 'count' ] };
- # offset, order by and page are not needed to count
- delete $attrs->{$_} for qw/rows offset order_by page pager/;
+ # offset, order by and page are not needed to count. record_filter is cdbi
+ delete $attrs->{$_} for qw/rows offset order_by page pager record_filter/;
($self->{count}) = (ref $self)->new($self->{source}, $attrs)->cursor->next;
}
return $self->class_registrations->{$class};
}
+=head2 source
+
+ my $source = $schema->source('Foo');
+
+Returns the result source object for the registered name
+
+=cut
+
+sub source {
+ my ($self, $class) = @_;
+ return $self->class_registrations->{$class}->result_source;
+}
+
+=head2 resultset
+
+ my $rs = $schema->resultset('Foo');
+
+Returns the resultset for the registered name
+
+=cut
+
+sub resultset {
+ my ($self, $class) = @_;
+ return $self->class_registrations->{$class}->result_source->resultset;
+}
+
+
=head2 load_classes [<classes>, (<class>, <class>), {<namespace> => [<classes>]}]
Uses L<Module::Find> to find all classes under the database class' namespace,
=cut
sub compose_connection {
- my ($class, $target, @info) = @_;
+ my ($self, $target, @info) = @_;
my $conn_class = "${target}::_db";
- $class->setup_connection_class($conn_class, @info);
- my $schema = $class->compose_namespace($target, $conn_class);
+ $self->setup_connection_class($conn_class, @info);
+ my $schema = $self->compose_namespace($target, $conn_class);
$schema->storage($conn_class->storage);
foreach my $class ($schema->registered_classes) {
my $source = $class->result_source;
$source->schema($schema);
$source->result_class($class);
$class->mk_classdata(result_source => $source);
+ $class->mk_classdata(resultset_instance => $source->resultset);
}
return $schema;
}
my $schema = bless({ }, $class);
while (my ($comp, $comp_class) = each %reg) {
my $target_class = "${target}::${comp}";
- $class->inject_base($target_class, $comp_class, $base);
+ $class->inject_base($target_class, $comp_class, ($base ? $base : ()));
@map{$comp, $comp_class} = ($target_class, $target_class);
}
$schema->class_registrations(\%map);