Skip Menu |
 

This queue is for tickets about the DBIx-Class CPAN distribution.

Report information
The Basics
Id: 76730
Status: open
Priority: 0/
Queue: DBIx-Class

People
Owner: Nobody in particular
Requestors: icestar [...] inbox.ru
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Subject: Resultset create method doesn't create related rows
Download (untitled) / with headers
text/plain 2.4k
Hi. According to the Resultset documentation on the create method (http://search.cpan.org/~arodland/DBIx-Class/lib/DBIx/Class/ResultSet.pm#create) I'm expecting it can create related rows in the related relationships. But on my attempt to insert related rows with the main one I get the error: "DBIx::Class::ResultSet::create(): Unable to determine relationship 'images' direction from 'Product', possibly due to a missing reverse-relationship on 'images' to 'Product'.". Please, take a look at my two tables schema. #========================================= package Related::Schema::Result::Product; use strict; use warnings; use base 'DBIx::Class'; __PACKAGE__->load_components("Core"); __PACKAGE__->table("Product"); __PACKAGE__->add_columns( 'id' => { data_type => 'int', is_auto_increment => 1, is_nullable => 0, }, 'itemId' => { data_type => 'varchar', size => 255, is_nullable => 0, }, 'data' => { data_type => 'blob', is_nullable => 0, }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->has_many( 'images' => 'Related::Schema::Result::ProductImage', { 'foreign.productId' => 'self.id' }, { cascade_delete => 1, join_type => 'left' } ); #========================================= package Related::Schema::Result::ProductImage; use strict; use warnings; use base 'DBIx::Class'; __PACKAGE__->load_components("Core"); __PACKAGE__->table("ProductImage"); __PACKAGE__->add_columns( 'id' => { data_type => 'int', is_auto_increment => 1, is_nullable => 0, }, 'productId' => { data_type => 'int', is_nullable => 0, }, 'url' => { data_type => 'varchar', size => 255, is_nullable => 0, }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->belongs_to( 'product' => 'Related::Schema::Result::Product', { 'foreign.id' => 'self.productId' }, { is_foreign_key_constraint => 0, join_type => 'inner' } ); #========================================= Below how I'm trying to insert the data my $product_row = $schema->resultset("Product")->create({ itemId => 'A1', data => "SERIALIZED PRODUCT DATA", images => [ { url => 'http://url1' }, { url => 'http://url2' } ], }); As you can see I have relationships in both directions: has_many and corresponding belongs_to. So even if I misunderstood the documentation and create method doesn't do the trick the error description doesn't explain the problem.
Which version of DBIx::Class is this? Does it also happen on 0.08196?
From: icestar [...] inbox.ru
Download (untitled) / with headers
text/plain 150b
On Thu Apr 26 02:05:13 2012, RIBASUSHI wrote: Show quoted text
> Which version of DBIx::Class is this? Does it also happen on 0.08196?
Yes, it also happens on 0.08196


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.