[Dbix-class] Alias column names
Bill Moseley
moseley at hank.org
Tue May 31 18:43:38 GMT 2011
On Thu, Apr 22, 2010 at 2:03 AM, Peter Rabbitson <rabbit+dbic at rabbit.us>wro=
te:
> 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 y=
ou
> 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 =3D> sub {
my ( $new, $self, $data, @rest ) =3D @_;
$data->{email_address} =3D 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
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20110531/6a8=
cb57c/attachment.htm
More information about the DBIx-Class
mailing list