[Dbix-class] create() with has_one related object broken

Hermida, Leandro Leandro.Hermida at fmi.ch
Thu Jun 4 13:38:21 GMT 2009


Hello,

 

Following the documentation it seems like create() with a has_one
related object is broken in 0.08103?

 

I have in MyDB::Study.pm

 

__PACKAGE__->load_components(qw( PK::Auto  Core ));

__PACKAGE__->table('study');

__PACKAGE__->add_columns('id' => {

                             data_type         => 'integer',

                             is_nullable       => 0,

                             is_auto_increment => 1,

                             extra             => { unsigned => 1 },

                         },

                         'name' => {

                             data_type         => 'varchar',

                             size              => 1000,

                             is_nullable       => 0,

                         },

                         'source_data_file_id_type' => {

                             data_type         => 'varchar',

                             size              => 100,

                             is_nullable       => 0,

                         },

                         'description' => {

                             data_type         => 'text',

                             is_nullable       => 1,

                         },);

__PACKAGE__->set_primary_key('id');

__PACKAGE__->has_one('source_data_file' =>
'MyDB::Study::SourceDataFile', 'study_id');

 

I have in MyDB::Study::SourceDataFile.pm

 

__PACKAGE__->load_components(qw( PK::Auto  Core ));

__PACKAGE__->table('study_source_data_file');

__PACKAGE__->add_columns('study_id' => {

                             accessor          => 'study',

                             data_type         => 'integer',

                             is_nullable       => 0,

                             is_foreign_key    => 1,

                             extra             => { unsigned => 1 },

                         },

                         'data' => {

                             data_type         => 'longtext',

                             is_nullable       => 0,

                         },);

__PACKAGE__->set_primary_key('study_id');

__PACKAGE__->belongs_to('study' => 'MyDB::Study', 'study_id');

 

 

If I try like the documentation says to do in create() with a  has_one
relationship, with an arrayref of hashrefs:

 

my $study = $odm_db->resultset('Study')->create(

    {

      name                     => $study_name,

      source_data_file_id_type => $id_type,

      description              => $study_desc,

      source_data_file         => [

          { data => $source_file_data }

      ],

    }

);

 

I get the error  "DBIx::Class::ResultSet::create(): new_result needs a
hash"

 

So then I just guessed and tried with just a hashref:

 

my $study = $odm_db->resultset('Study')->create(

    {

      name                     => $study_name,

      source_data_file_id_type => $id_type,

      description              => $study_desc,

      source_data_file         => {

          data => $source_file_data

      },

    }

);

 

And here I get another error  "DBIx::Class::ResultSet::create(): DBI
Exception: DBD::mysql::st execute failed: Incorrect integer value:
'MyDB::Study=HASH(0x7f915d105068)' for column 'study_id' at row 1 [for
Statement "INSERT INTO study_source_data_file ( data, study_id) VALUES (
?, ? )" with ParamValues: 0='<data here...>',
1='MyDB::Study=HASH(0x7f915d105068)']"
 
What could I be doing wrong?
 
Leandro
 
 
 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20090604/1eaaa82e/attachment.htm


More information about the DBIx-Class mailing list