From: Christopher H. Laco Date: Sat, 1 Apr 2006 23:54:12 +0000 (+0000) Subject: Added remove_column(s) from ResultSource/ResultSourceProxy X-Git-Tag: v0.07002~75^2~253 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=002a359a8e58e2ffdc2b571231a8a6f209056ffe;p=dbsrgits%2FDBIx-Class.git Added remove_column(s) from ResultSource/ResultSourceProxy Added add_column alias to ResultSourceProxy --- diff --git a/Changes b/Changes index 7f51a67..f31680c 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for DBIx::Class + - added remove_column(s) to ResultSource/ResultSourceProxy + - added add_column alias to ResultSourceProxy + 0.06001 - Added fix for quoting with single table @@ -66,7 +69,7 @@ Revision history for DBIx::Class - remove build dependency on version.pm 0.05004 2006-02-13 20:59:00 - - allow specification of related columns via cols attr when primary + - allow specification of related columns via cols attr when primary keys of the related table are not fetched - fix count for group_by as scalar - add horrific fix to make Oracle's retarded limit syntax work diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index 68d16b2..53da27b 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -127,7 +127,7 @@ Convenience alias to add_columns. sub add_columns { my ($self, @cols) = @_; $self->_ordered_columns(\@cols) unless $self->_ordered_columns; - + my @added; my $columns = $self->_columns; while (my $col = shift @cols) { @@ -205,6 +205,41 @@ sub columns { return @{$self->{_ordered_columns}||[]}; } +=head2 remove_columns + + $table->remove_columns(qw/col1 col2 col3/); + +Removes columns from the result source. + +=head2 remove_column + + $table->remove_column('col'); + +Convenience alias to remove_columns. + +=cut + +sub remove_columns { + my ($self, @cols) = @_; + + return unless $self->_ordered_columns; + + my $columns = $self->_columns; + my @remaining; + + foreach my $col (@{$self->_ordered_columns}) { + push @remaining, $col unless grep(/$col/, @cols); + } + + foreach (@cols) { + undef $columns->{$_}; + }; + + $self->_ordered_columns(\@remaining); +} + +*remove_column = \&remove_columns; + =head2 set_primary_key =over 4 @@ -339,11 +374,11 @@ the SQL 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: - + CD->might_have(liner_notes => 'LinerNotes', undef, { proxy => [ qw/notes/ ], }); - + Then, assuming LinerNotes has an accessor named notes, you can do: my $cd = CD->find(1); diff --git a/lib/DBIx/Class/ResultSourceProxy.pm b/lib/DBIx/Class/ResultSourceProxy.pm index 3ae7ad6..d1f5b80 100644 --- a/lib/DBIx/Class/ResultSourceProxy.pm +++ b/lib/DBIx/Class/ResultSourceProxy.pm @@ -22,6 +22,8 @@ sub add_columns { } } +*add_column = \&add_columns; + sub has_column { my ($self, $column) = @_; return $self->result_source_instance->has_column($column); @@ -32,11 +34,17 @@ sub column_info { return $self->result_source_instance->column_info($column); } - + sub columns { return shift->result_source_instance->columns(@_); } - + +sub remove_columns { + return shift->result_source_instance->remove_columns(@_); +} + +*remove_column = \&remove_columns; + sub set_primary_key { shift->result_source_instance->set_primary_key(@_); }