Revision history for DBIx::Class
+0.05001
+ - added experimental Serialize and ResultSetManager components
+ - fix to find() for complex resultsets
+ - added of $storage->debugcb(sub { ... })
+ - added $source->resultset_attributes accessor
+ - added include_columns rs attr
+
0.05000 2006-02-01 16:48:30
- assorted doc fixes
- remove ObjectCache, not yet working in 0.05
# i.e. first release of 0.XX *must* be 0.XX000. This avoids fBSD ports
# brain damage and presumably various other packaging systems too
-$VERSION = '0.05000';
+$VERSION = '0.05001';
sub MODIFY_CODE_ATTRIBUTES {
my ($class,$code,@attrs) = @_;
$attrs->{select} = [ map { m/\./ ? $_ : "${alias}.$_" } @cols ];
}
$attrs->{as} ||= [ map { m/^$alias\.(.*)$/ ? $1 : $_ } @{$attrs->{select}} ];
+ if (my $include = delete $attrs->{include_columns}) {
+ push(@{$attrs->{select}}, @$include);
+ push(@{$attrs->{as}}, map { m/([^\.]+)$/; $1; } @$include);
+ }
#use Data::Dumper; warn Dumper(@{$attrs}{qw/select as/});
$attrs->{from} ||= [ { $alias => $source->from } ];
if (my $join = delete $attrs->{join}) {
C<me.> onto the start of any column without a C<.> in it and sets C<select>
from that, then auto-populates C<as> from C<select> as normal.
+=head2 include_columns (arrayref)
+
+Shortcut to include additional columns in the returned results - for example
+
+ { include_columns => ['foo.name'], join => ['foo'] }
+
+would add a 'name' column to the information passed to object inflation
+
=head2 select (arrayref)
Indicates which columns should be selected from the storage. You can use
__PACKAGE__->load_components(qw/AccessorGroup/);
__PACKAGE__->mk_group_accessors('simple' =>
- qw/_ordered_columns _columns _primaries _unique_constraints name resultset_class result_class schema from _relationships/);
+ qw/_ordered_columns _columns _primaries _unique_constraints name resultset_class resultset_attributes result_class schema from _relationships/);
=head1 NAME
$class = ref $class if ref $class;
my $new = bless({ %{$attrs || {}} }, $class);
$new->{resultset_class} ||= 'DBIx::Class::ResultSet';
+ $new->{resultset_attributes} = { %{$new->{resultset_attributes} || {}} };
$new->{_ordered_columns} = [ @{$new->{_ordered_columns}||[]}];
$new->{_columns} = { %{$new->{_columns}||{}} };
$new->{_relationships} = { %{$new->{_relationships}||{}} };
return $new;
}
+=head2 add_columns
+
+ $table->add_columns(qw/col1 col2 col3/);
+
+ $table->add_columns('col1' => \%col1_info, 'col2' => \%col2_info, ...);
+
+Adds columns to the result source. If supplied key => hashref pairs uses
+the hashref as the column_info for that column.
+
+=head2 add_column
+
+ $table->add_column('col' => \%info?);
+
+Convenience alias to add_columns
+
+=cut
+
sub add_columns {
my ($self, @cols) = @_;
$self->_ordered_columns( \@cols )
*add_column = \&add_columns;
-=head2 add_columns
-
- $table->add_columns(qw/col1 col2 col3/);
-
- $table->add_columns('col1' => \%col1_info, 'col2' => \%col2_info, ...);
-
-Adds columns to the result source. If supplied key => hashref pairs uses
-the hashref as the column_info for that column.
-
-=head2 add_column
-
- $table->add_column('col' => \%info?);
-
-Convenience alias to add_columns
-
-=cut
-
-sub resultset {
- my $self = shift;
- return $self->resultset_class->new($self);
-}
-
=head2 has_column
if ($obj->has_column($col)) { ... }
prefixed relative to the current source, in accordance with where they appear
in the supplied relationships. Examples:
- my $source = $schema->$resultset('Tag')->source;
+ my $source = $schema->resultset('Tag')->source;
@columns = $source->resolve_prefetch( { cd => 'artist' } );
# @columns =
return $self->schema->source($self->relationship_info($rel)->{source});
}
-1;
+=head2 resultset
+
+Returns a resultset for the given source created by calling
+
+$self->resultset_class->new($self, $self->resultset_attributes)
+
+=head2 resultset_class
+
+Simple accessor.
+
+=head2 resultset_attributes
+
+Simple accessor.
+
+=cut
+
+sub resultset {
+ my $self = shift;
+ return $self->resultset_class->new($self, $self->{resultset_attributes});
+}
+
+=cut
=head2 throw_exception
use base qw/DBIx::Class/;
-sub iterator_class { shift->result_source_instance->resultset_class(@_) }
+sub iterator_class { shift->result_source_instance->resultset_class(@_) }
sub resultset_class { shift->result_source_instance->resultset_class(@_) }
+sub resultset_attributes {
+ shift->result_source_instance->resultset_attributes(@_);
+}
+
sub add_columns {
my ($class, @cols) = @_;
my $source = $class->result_source_instance;
sub run_tests {
my $schema = shift;
-plan tests => 36;
+plan tests => 38;
my @art = $schema->resultset("Artist")->search({ }, { order_by => 'name DESC'});
$cd = $schema->resultset("CD")->search({ title => 'Spoonful of bees' }, { cols => ['title'] })->next;
is($cd->title, 'Spoonful of bees', 'subset of columns returned correctly');
+$cd = $schema->resultset("CD")->search(undef, { include_columns => [ 'artist.name' ], join => [ 'artist' ] })->find(1);
+
+is($cd->title, 'Spoonful of bees', 'Correct CD returned with include');
+is($cd->get_column('name'), 'Caterwauler McCrae', 'Additional column returned');
+
# insert_or_update
$new = $schema->resultset("Track")->new( {
trackid => 100,