Hi everyone!

From the ResultSet documentation on the create method (http://search.cpan.org/~arodland/DBIx-Class/lib/DBIx/Class/ResultSet.pm#create) I understood that it's able to create related rows in related relationships. But on my attempt to create the main row with some related 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'."

My Product table is described below:
__PACKAGE__->load_components("Core");
__PACKAGE__->table("Product");
__PACKAGE__->add_columns(
    'id' => {
        data_type => 'int',
        is_auto_increment => 1,
        is_nullable => 0,
    },
    'productId' => {
        data_type => 'varchar',
        size => 255,
        is_nullable => 0,
    },
    'data' => {
        data_type => 'blob',
        is_nullable => 0,
    },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->has_many(
    'images' => 'My::Result::ProductImage',
    { 'foreign.productId' => 'self.id' },
    { cascade_delete => 1, join_type => 'left' }
);

Here is my ProductImage table:
__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' => 'My::Result::Product',
    { 'foreign.id' => 'self.productId' },
    { is_foreign_key_constraint => 0, join_type => 'inner' }
);

I'm trying to perform the insertion like that:
my $product_row = $schema->resultset("Product")->create({
    productId => $product->{id},
    data      => $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.
Can you help me to find the problem what I'm dong wrong?
Maybe I misunderstood the documentation and create doesn't do the trick?

--
Dmitry Bigunyak
e-mail: ices...@inbox.ru


_______________________________________________
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@lists.scsys.co.uk

Reply via email to