On Thu, Apr 22, 2010 at 2:03 AM, Peter Rabbitson <rabbit+d...@rabbit.us>wrote:

> Bill Moseley wrote:
> > Is there a way in DBIC to alias column names?  I know I can specify an
> > accessor name (and create wrapper accessors using different names), but
> > I'm looking for a way to alias column names to use both as accessors and
> > when calling create().
> >
>
> Column aliasing is only worth it if it becomes uniform (i.e. works with
> search() among other things). Since the current SQLA1.5x WHERE
> specification
> can not be safely introspected, it is impractical to introduce any sort of
> dbic-wide column aliasing. Help out with the SQLA2 development and what you
> want will become reality fairly quickly :)
>

Can you think of any short-term work-around?  I can define a separate
"accessor" for the column, and that works fine, but the difficulty is where
I pass in a hash of column data, it seems.  The has_column() method tends to
catch this.

Again, I have two schema objects pointing to very similar databases.  And in
one User has an "email" column and in the other schema the column name is
"email_address".

I can define the accessor to be "email" in both.  For create I suppose I
could do something like:

around new => sub {
    my ( $new, $self, $data, @rest ) = @_;
    $data->{email_address} = delete $data->{email};
    return $self->$new( $data, @rest );
};


And likewise wrap the update() method.

But, I suspect that will only work for the most trivial usages (like above)
and will fail with anything more interesting.


-- 
Bill Moseley
mose...@hank.org
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk

Reply via email to