2

I have started to use DBIx::Class and I really like it for the most part but what is really starting to annoy me is the column alias does not seem to work fully.

Eg. Suppose I have this table definition:

#TestClass.pm

use strict;
use warnings;

package Database::Schema::Result::TestClass;

use base qw/DBIx::Class::Core/;

__PACKAGE__->table("TEST_TABLE");
__PACKAGE__->add_column("ID")
__PACKAGE__->add_columns(NAME => {accessor => "name"},
                         VALUE => {accessor => "value"}
                         );

And then I try to create a new row as follows:

 $schema->resultset("TestClass")->create(name => "test", value => "value");

The above will say: DBIx::Class::ResultSet::create(): No such column name on Database::Schema::Result::TestClass

However the following works fine:

 $schema->resultset("TestClass")->create(NAME => "test", VALUE => "value");

If later on I have TestClass object and try to access its columns as such:

 $object->NAME;

I get Can't locate object method "NAME" via package "Database::Schema::Result::TestClass"

but this is ok:

 $object->name

I would expect to be able to create the object using the accessor I provided the column and for creation of the object and accessing the columns to be consistent but this does not seem to be the case. Can anyone explain why this is?

2
  • 1
    "does not work" is not a useful error description, please paste the actual error message! Nov 1, 2012 at 17:08
  • 2
    You're telling add_columns NAME and VALUE but you're telling create name and value. SQL may be case insensitive but DBIx::Class probably isn't.
    – Schwern
    Nov 1, 2012 at 17:15

1 Answer 1

0

I think the answer to your dilemma lies in part 3 of the DBIx::Class Tutorial. Also, the manual page for the add_columns method of DBIx::Class::ResultSource class states that: Use this (the accessor property) to set the name of the accessor method for this column. If unset, the name of the column will be used.

Basically what you did was to define a column NAME and create an accessor for it name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.