Skip Menu |

This queue is for tickets about the Fey CPAN distribution.

Report information
The Basics
Id: 40857
Status: resolved
Priority: 0/
Queue: Fey

People
Owner: Nobody in particular
Requestors: ARISTOTLE [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.15
Fixed in: 0.33



Subject: Add `aliased_column`/`aliased_columns` methods to Fey::Table::Alias
It would be nice if I could do this: Fey::Table->alias( 'foo' )->aliased_column( 'bar' ) as a shortcut for Fey::Table->alias( 'foo' ) ->column( 'bar' )->alias( alias_name => 'foo_bar' ) The win becomes much bigger for `columns`, where the equivalent to Fey::Table->alias( 'foo' )->aliased_columns( qw/ bar baz quux / ) is a highly awkward construction like map { $_->alias( alias_name => 'foo_' . $_->name ) } Fey::Table->alias( 'foo' )->columns( qw/ bar baz quux / )
Actually, this would be nice to have on Fey::Table also, not just Fey::Table::Alias, for cases where one is joining tables that have identically named columns and one wants the columns from both tables.
On Wed Nov 12 07:35:25 2008, ARISTOTLE wrote: Show quoted text
> It would be nice if I could do this: > > Fey::Table->alias( 'foo' )->aliased_column( 'bar' )
This a little confusing, since there's already an alias() method for Fey::Table objects, but with a different API. Are you saying the argument to ->alias() in your example would be used as a prefix for the aliased column names? I think that'd need a different API.
On Fri Nov 14 18:11:22 2008, DROLSKY wrote: Show quoted text
> On Wed Nov 12 07:35:25 2008, ARISTOTLE wrote:
> > It would be nice if I could do this: > > > > Fey::Table->alias( 'foo' )->aliased_column( 'bar' )
> > This a little confusing, since there's already an alias() method for > Fey::Table objects, but with a different API.
Yes, my bad. Please imagine all of my examples with `alias_name =>` included where it is missing. (This is an annoyingly verbose aspect of the Fey API, btw.) Show quoted text
> Are you saying the argument to ->alias() in your example would be used > as a prefix for the aliased column names?
Yes, see the `map` example. Show quoted text
> I think that'd need a different API.
I am open to suggestions (it would be nice to be able to pick a separator, instead of `_` being hardcoded), as long as it remains convenient.
The way this was implemented means that calling just $table_alias->aliased_columns does nothing useful, and if one wants aliased versions of all of a table's columns, one has to write $table_alias->aliased_columns( map { $_->name } $table_alias->columns ) instead. This is too awkward for any practical purposes. Attached is a patch which fixes this.
diff -r 40f853ef26cf lib/Fey/Table.pm --- a/lib/Fey/Table.pm Thu Sep 10 14:06:25 2009 -0500 +++ b/lib/Fey/Table.pm Mon Sep 14 21:33:50 2009 +0200 @@ -287,19 +287,14 @@ my $self = shift; my $prefix = shift; my $name = shift; - - my $col = $self->column($name) - or return; - - return $col->alias( alias_name => $prefix . $col->name() ); + return $self->aliased_columns( $prefix, $name ); } sub aliased_columns { my $self = shift; my $prefix = shift; - - return map { $self->aliased_column( $prefix, $_ ) } @_; + return map { $_ && $_->alias( alias_name => $prefix . $_->name() ) } $self->columns( @_ ); } sub sql