X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSet.pm;h=4e8467eaad5bc96bb67136995511f7e8464323dc;hb=7e51afbf1951bc8febf00897e5e3f0f25dfc34aa;hp=ca0712df3108716f14921e6ee6b7b18b5eb66afe;hpb=f67d8c67c800d277e9c0ec20a72ca2d9496c8d80;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index ca0712d..4e8467e 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -2094,6 +2094,49 @@ sub related_resultset { }; } +=head2 current_source_alias + +=over 4 + +=item Arguments: none + +=item Return Value: $source_alias + +=back + +Returns the current table alias for the result source this resultset is built +on, that will be used in the SQL query. Usually it is C. + +Currently the source alias that refers to the result set returned by a +L/L family method depends on how you got to the resultset: it's +C by default, but eg. L aliases it to the related result +source name (and keeps C referring to the original result set). The long +term goal is to make L always alias the current resultset as C +(and make this method unnecessary). + +Thus it's currently necessary to use this method in predefined queries (see +L) when referring to the +source alias of the current result set: + + # in a result set class + sub modified_by { + my ($self, $user) = @_; + + my $me = $self->current_source_alias; + + return $self->search( + "$me.modified" => $user->id, + ); + } + +=cut + +sub current_source_alias { + my ($self) = @_; + + return ($self->{attrs} || {})->{alias} || 'me'; +} + sub _resolve_from { my ($self, $extra_join) = @_; my $source = $self->result_source; @@ -2375,6 +2418,10 @@ L) you will need to do C<\'year DESC' > specify an order. (The scalar ref causes it to be passed as raw sql to the DB, so you will need to manually quote things as appropriate.) +If your L version supports it (>=1.50), you can also use +C<{-desc => 'year'}>, which takes care of the quoting for you. This is the +recommended syntax. + =head2 columns =over 4