create() with has_one related object broken

7 messages Options
Embed this post
Permalink
Hermida, Leandro

create() with has_one related object broken

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)

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
 
 
 

 


_______________________________________________
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@...
Peter Rabbitson-2

Re: create() with has_one related object broken

Reply Threaded More More options
Print post
Permalink
Hermida, Leandro wrote:

> 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?
>

Not sure at this point. Could you package your test schema and send it
along with the tests above as a tarball to the list? Thanks.

_______________________________________________
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@...
Peter Rabbitson-2

Re: create() with has_one related object broken

Reply Threaded More More options
Print post
Permalink
In reply to this post by Hermida, Leandro
Hermida, Leandro wrote:

> 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?
>

Also did this work on 0.08102 ?

_______________________________________________
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@...
Matt S Trout

Re: create() with has_one related object broken

Reply Threaded More More options
Print post
Permalink
In reply to this post by Hermida, Leandro
On Thu, Jun 04, 2009 at 03:38:21PM +0200, Hermida, Leandro wrote:
> If I try like the documentation says to do in create() with a  has_one
> relationship, with an arrayref of hashrefs:

arrayref is for has_many.

For might_have/belongs_to/has_one there's only one so you just pass a
hashref.

If the docs don't make this clear, please supply a patch :)

--
        Matt S Trout         Catalyst and DBIx::Class consultancy with a clue
     Technical Director      and a commit bit: http://shadowcat.co.uk/catalyst/
 Shadowcat Systems Limited
  mst (@) shadowcat.co.uk        http://shadowcat.co.uk/blog/matt-s-trout/

_______________________________________________
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@...
Hermida, Leandro

RE: create() with has_one related object broken

Reply Threaded More More options
Print post
Permalink

On Thu, Jun 04, 2009 at 03:38:21PM +0200, Hermida, Leandro wrote:
>> If I try like the documentation says to do in create() with a
has_one
>> relationship, with an arrayref of hashrefs:


> arrayref is for has_many.
>
> For might_have/belongs_to/has_one there's only one so you just pass a
> hashref.
>
> If the docs don't make this clear, please supply a patch :)

Hi,

My apologies, there must be an error in the docs
http://search.cpan.org/~ribasushi/DBIx-Class-0.08103/lib/DBIx/Class/Resu
ltSet.pm#create.  It clearly states, "For has_many and has_one
relationships, pass an arrayref of hashrefs containing the data for each
of the rows to create in the foreign tables, again using the
relationship name as the key." and then further down, "Example of
creating a new row and also creating rows in a related has_many or
has_one resultset. Note Arrayref."

Also, I tried just one hashref as it made more sense and it still
doesn't work, please see second error I got in original email.

Leandro


_______________________________________________
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@...
Peter Rabbitson-2

Re: create() with has_one related object broken

Reply Threaded More More options
Print post
Permalink
Hermida, Leandro wrote:

> On Thu, Jun 04, 2009 at 03:38:21PM +0200, Hermida, Leandro wrote:
>>> If I try like the documentation says to do in create() with a
> has_one
>>> relationship, with an arrayref of hashrefs:
>
>
>> arrayref is for has_many.
>>
>> For might_have/belongs_to/has_one there's only one so you just pass a
>> hashref.
>>
>> If the docs don't make this clear, please supply a patch :)
>
> Hi,
>
> My apologies, there must be an error in the docs
> http://search.cpan.org/~ribasushi/DBIx-Class-0.08103/lib/DBIx/Class/Resu
> ltSet.pm#create.  It clearly states, "For has_many and has_one
> relationships, pass an arrayref of hashrefs containing the data for each
> of the rows to create in the foreign tables, again using the
> relationship name as the key." and then further down, "Example of
> creating a new row and also creating rows in a related has_many or
> has_one resultset. Note Arrayref."
>
> Also, I tried just one hashref as it made more sense and it still
> doesn't work, please see second error I got in original email.
>

And you still haven't replied to my questions.

_______________________________________________
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@...
Peter Rabbitson-2

Re: create() with has_one related object broken

Reply Threaded More More options
Print post
Permalink
In reply to this post by Hermida, Leandro
Hermida, Leandro wrote:

> 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?
>

I fixed the documentation, and wrote a test specifically testing your
use case. Everything works as expected, not sure what you did to make
it blow up.
http://dev.catalyst.perl.org/svnweb/bast/revision?rev=6967

Cheers

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