[Dbix-class] create failures with has_one
Dermot
paikkos at googlemail.com
Wed Oct 14 16:10:57 GMT 2009
Hi,
I have had a number of errors trying to add a record to a SQLite3 db
and DBIx '0.08010';
The original error was:
DBIx::Class::ResultSet::update_or_create(): Object ARRAY(0x8f3f7a8)
isn't a My::Schema::MotionDB::
I created a small test to see if I could narrow it down but that is
throwing this exception:
DBIx::Class::ResultSet::update_or_create(): DBI Exception:
DBD::SQLite::db prepare_cached failed: near "CONTRIB": syntax error(1)
at dbdimp.c line 271 [for Statement "SELECT me.id, me.sub_id,
me.contrib_id FROM clipData me WHERE ( ( ( ( me.id CONTRIB ID ? ) ) )
)"] at t/test_update_or_create.t line 45
I can't find 'CONTRIB ID' anywhere on my sources. I have parred my
schema and script down to the bone but as long as I try and create a
row with a row in a related (has_one) table, I get errors.
Can anyone spot where I am going wrong?
TIA,
Dp.
#!/usr/local/bin/perl
use strict;
use warnings;
use FindBin qw($Bin);
use Path::Class;
use lib dir ($Bin,'..','lib')->stringify;
use My::Schema::MotionDB;
use Config::General;
use Data::Dumper;
my $debug = 1;
my $path = $Bin.'..';
my @configPath = ($path, $Bin);
my $config = new Config::General(-ConfigFile => 'motion.conf',
-ConfigPath=> \@configPath, -BackslashEscape => 1);
my %config = $config->getall;
my $HOME = dir($Bin, '..');
my $dsn = $config{'Model::MotionDB'}{'connect_info'}[0];
$dsn =~ s/__HOME__/$HOME/;
print "DSN=$dsn CONF=$config{'Model::MotionDB'}{'connect_info'}[0]\n"
if $debug == 1;
my $schema = My::Schema::MotionDB->connect($dsn) ||
die "Failed fo connect to the database at $dsn $!\n";
my $record = {
'validation_pass' => 1,
'files' => [],
'active' => 1,
'name' => 'Gustav MR',
'clipdata' => [
{
'contrib_id' => 2,
}
],
'contrib_id' => 2,
};
print Dumper ($record);
my $row = $schema->resultset('Submissions')->update_or_create($record,
{key => 'name_unique'});
print STDERR "Adding record\n" if $debug == 1;
==============
package My::Schema::MotionDB::Submissions;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components("Core");
__PACKAGE__->table("submissions");
__PACKAGE__->add_columns(
"id",
{ data_type => "INTEGER", is_nullable => 0, size => undef },
"name",
{ data_type => "VARCHAR", is_nullable => 0, size => 10 },
"contrib_id",
{ data_type => "INTEGER", is_nullable => 0, size => undef },
"active",
{ data_type => "INTEGER", is_nullable => 0, size => undef },
"validation_pass",
{ data_type => "INTEGER", is_nullable => 0, size => undef },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->add_unique_constraint("name_unique", ["name"]);
__PACKAGE__->belongs_to(
contrib_id => 'My::Schema::MotionDB::Contributors',
);
__PACKAGE__->has_one(
clipdata => 'My::Schema::MotionDB::Clipdata', 'sub_id'
);
__PACKAGE__->has_many(
files => 'My::Schema::MotionDB::Files', 'sub_id'
1;
package My::Schema::MotionDB::Clipdata;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components("Core");
__PACKAGE__->table("clipData");
__PACKAGE__->add_columns(
"id",
{ data_type => "INTEGER", is_nullable => 0, size => undef },
"sub_id",
{ data_type => "INTEGER", is_nullable => 0, size => undef },
"contrib_id",
{ data_type => "INTEGER", is_nullable => 0, size => undef },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->add_unique_constraint(
unique_sub => [ qw/sub_id/]
);
__PACKAGE__->belongs_to(
submission =>
'My::Schema::MotionDB::Submissions', 'sub_id');
__PACKAGE__->belongs_to(
contributor =>
'My::Schema::MotionDB::Contributors', 'contrib_id');
1;
================================
More information about the DBIx-Class
mailing list