X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSource.pm;h=ceb5d3675187b3d67d97d91b00b2e478f2984f4e;hb=5ac6a04477849fabc50271c5b7ab15a080ae0109;hp=dcc57ad4360c2049bdf30a45b129bb05762313e7;hpb=701da8c4d6f0b78ffc015085aa410a6cacfcdb40;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index dcc57ad..ceb5d36 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -12,7 +12,7 @@ use base qw/DBIx::Class/; __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 @@ -34,6 +34,7 @@ sub new { $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}||{}} }; @@ -41,6 +42,23 @@ sub new { 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 ) @@ -63,28 +81,6 @@ sub add_columns { *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)) { ... } @@ -257,7 +253,7 @@ command immediately before C. An arrayref containing a list of accessors in the foreign class to proxy in the main class. If, for example, you do the following: - __PACKAGE__->might_have(bar => 'Bar', undef, { proxy => qw[/ margle /] }); + __PACKAGE__->might_have(bar => 'Bar', undef, { proxy => [ qw/margle/ ] }); Then, assuming Bar has an accessor named margle, you can do: @@ -415,7 +411,7 @@ array of column names for each of those relationships. Column names are 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 = @@ -496,7 +492,28 @@ sub related_source { 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