name collision

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

name collision

Jeremy J. Koch

I have the luck of a table with a column named "source_name".

This of course results in a hilarious situation:
DBIx::Class::Row::get_column(): Can't fetch data as class method at (eval 6724)

Normally I would take the easy route and rename the column.  Unfortunately
the schema is defined by a proprietary application I am integrating with so
this is not an option.  The only solution I could come up with was to omit
"source_name" column from the schema class.  Then to use +select with +as
resultset attributes to specify an a different name for the column.

Any thoughts?  Have I overlooked a simpler solution?

Thank you,
-Jeremy


---

package MyApplication::Schema::TableName;

use strict;
use warnings;

use base 'DBIx::Class';

__PACKAGE__->load_components("Core");
__PACKAGE__->table("TableName");
__PACKAGE__->add_columns(
  "session_id",
  {
    data_type => "int identity",
    default_value => undef,
    is_nullable => 0,
    size => 10,
  },
  "created_date",
  { data_type => "datetime", default_value => 3, is_nullable => 0, size => 23 },
  "source_name",
  {
    data_type => "varchar",
    default_value => undef,
    is_nullable => 0,
    size => 255,
  },
);

_______________________________________________
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@...
Reply | Threaded
Open this post in threaded view
|

Re: name collision

Jeremy J. Koch
From: Jeremy J. Koch <[hidden email]>
Subject: name collision
Date: Thu, 03 Jul 2008 16:21:52 -0400 (EDT)

> I have the luck of a table with a column named "source_name".
>
> This of course results in a hilarious situation:
> DBIx::Class::Row::get_column(): Can't fetch data as class method at (eval 6724)
>
> Normally I would take the easy route and rename the column.  Unfortunately
> the schema is defined by a proprietary application I am integrating with so
> this is not an option.  The only solution I could come up with was to omit
> "source_name" column from the schema class.  Then to use +select with +as
> resultset attributes to specify an a different name for the column.
>
> Any thoughts?  Have I overlooked a simpler solution?

Replying to my own message is probably bad form...

I found the answer in the ResultSource documentation.

Sorry for the noise!

-Jeremy


_______________________________________________
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@...
Reply | Threaded
Open this post in threaded view
|

Re: name collision

claco
In reply to this post by Jeremy J. Koch
Jeremy J. Koch wrote:

> I have the luck of a table with a column named "source_name".
>
> This of course results in a hilarious situation:
> DBIx::Class::Row::get_column(): Can't fetch data as class method at (eval 6724)
>
> Normally I would take the easy route and rename the column.  Unfortunately
> the schema is defined by a proprietary application I am integrating with so
> this is not an option.  The only solution I could come up with was to omit
> "source_name" column from the schema class.  Then to use +select with +as
> resultset attributes to specify an a different name for the column.
>
> Any thoughts?  Have I overlooked a simpler solution?
>
> Thank you,
> -Jeremy
Have you tried setting the accessor key of the column_info for that column?

I wonder if this is a column name collision, or just that code is trying
to access ->source_name at a higher level....

-=Chris


_______________________________________________
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@...

signature.asc (194 bytes) Download Attachment