mysqlperldbix-classdancer

DBIx::Class Error on New and Create


I am using DBIx::Class in a Dancer2 project to talk to a MySQL database. Within that project, I have a ClassInfo resultset that I can select from, search, delete and update, without problem.

However, whenever I try to add a new row, via:

my $new_class = $SCHEMA->resultset( 'ClassInfo' )->new({});

or

my $new_class = $SCHEMA->resultset( 'ClassInfo' )->create({});

(data left out for brevity), I receive the following error:

DBIx::Class::Row::has_column_loaded(): Can't call has_column data as class method at /home/jlamey/src/dancer_projects/QP/bin/../lib/QP.pm line 2109

2104      {
2105        flash error => sprintf( 'Class <strong>%s</strong> already exists.' );
2106        redirect '/admin/manage_classes/classes';
2107      }
2108    
2109      my $new_class = $SCHEMA->resultset( 'ClassInfo' )->new(
2110        {
2111          title                => body_parameters->get( 'title' ),
2112          description          => body_parameters->get( 'description' ),
2113          class_group_id       => body_parameters->get( 'class_group_id' ),
2114          class_subgroup_id    => ( body_parameters->get( 'class_subgroup_id' )    ? body_parameters->get( 'class_subgroup_id' )    : undef ),

I have even tried submitting both a 'new' and a 'create' command with zero data, just to ensure it's not the data that's causing the error, and the error is still thrown.

The table it's trying to write to looks like this:

+----------------------+---------------------+------+-----+---------+----------------+
| Field                | Type                | Null | Key | Default | Extra          |
+----------------------+---------------------+------+-----+---------+----------------+
| id                   | int(8) unsigned     | NO   | PRI | NULL    | auto_increment |
| class_group_id       | int(8) unsigned     | NO   | MUL | 1       |                |
| class_subgroup_id    | int(8) unsigned     | YES  | MUL | NULL    |                |
| teacher_id           | int(8) unsigned     | YES  | MUL | NULL    |                |
| secondary_teacher_id | int(8) unsigned     | YES  | MUL | NULL    |                |
| tertiary_teacher_id  | int(8) unsigned     | YES  | MUL | NULL    |                |
| title                | varchar(255)        | NO   | MUL |         |                |
| description          | text                | NO   |     | NULL    |                |
| num_sessions         | varchar(255)        | YES  |     | NULL    |                |
| fee                  | varchar(100)        | YES  |     | NULL    |                |
| skill_level          | varchar(255)        | YES  |     | NULL    |                |
| is_also_embroidery   | tinyint(1) unsigned | YES  | MUL | 0       |                |
| is_also_club         | tinyint(1) unsigned | YES  | MUL | 0       |                |
| show_club            | tinyint(1) unsigned | YES  |     | 0       |                |
| image_filename       | varchar(255)        | YES  |     | NULL    |                |
| supply_list_filename | varchar(255)        | YES  |     | NULL    |                |
| no_supply_list       | tinyint(1) unsigned | YES  |     | 0       |                |
| always_show          | tinyint(1) unsigned | YES  |     | 0       |                |
| anchor               | varchar(5)          | YES  |     | NULL    |                |
| new                  | tinyint(1) unsigned | YES  |     | 0       |                |
+----------------------+---------------------+------+-----+---------+----------------+

And the resultset looks like:

package QP::Schema::Result::ClassInfo;

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

__PACKAGE__->table( 'classes' );

__PACKAGE__->add_columns(
                          id =>
                          {
                            data_type         => 'integer',
                            size              => 8,
                            is_nullable       => 0,
                            is_auto_increment => 1,
                          },
.
.
.
                          new =>
                          {
                            data_type         => 'boolean',
                            is_nullable       => 0,
                            default_value     => 0,
                          },
                        );

__PACKAGE__->set_primary_key( 'id' );

__PACKAGE__->belongs_to( teacher     => 'QP::Schema::Result::Teacher',       'teacher_id' );
__PACKAGE__->belongs_to( teacher2    => 'QP::Schema::Result::Teacher',       'secondary_teacher_id' );
__PACKAGE__->belongs_to( teacher3    => 'QP::Schema::Result::Teacher',       'tertiary_teacher_id' );
__PACKAGE__->belongs_to( class_group => 'QP::Schema::Result::ClassGroup',    'class_group_id' );
__PACKAGE__->belongs_to( subgroup    => 'QP::Schema::Result::ClassSubgroup', 'class_subgroup_id' );

__PACKAGE__->has_many( dates => 'QP::Schema::Result::ClassDate', 'class_id' );

1;

I'm at a loss; no other resultset in this project has this issue, and they're all built the same way.

Thanks in advance for any help. -- Jason


Solution

  • You have a column named new which creates an accessor method named new resulting in overriding the classes' constructor method. This is similar to DBIx::Class::Manual::Troubleshooting/syntax error at or near "" ....