Hi everyone!

I am new here - a cdbi convert.

I am creating a record with its has_many relationship and, though create succeeds, I wind up with data in the has_many table without the foreign key.

Here is the data that goes into create:

$VAR1 = {
          'features' => [
                          {
                            'feature_id' => undef,
                            'feature' => 'kdkdk',
                            'ord' => '1'
                          },
                          {
                            'feature_id' => undef,
                            'feature' => 'kdkdkdk',
                            'ord' => '2'
                          },
                          {
                            'feature_id' => undef,
                            'feature' => 'jjjj',
                            'ord' => '3'
                          }
                        ],
          'sku' => 'cccc',
          'name' => 'kdkdk',
          'description' => 'kdkdkdk'
        };

The relationship's foreign key is product_id - it is created as a result of the main insert - but is not propagated into the feature table. Here are the inserts:

INSERT INTO product (description, name, sku) VALUES (?, ?, ?): 'kdkdkdk', 'kdkdk', 'cccc' SELECT COUNT( * ) FROM product_feature me WHERE ( feature = ? AND feature_id IS NULL AND ord = ? ): 'kdkdk', '1' INSERT INTO product_feature (feature, feature_id, ord) VALUES (?, ?, ?): 'kdkdk', 'NULL', '1' SELECT COUNT( * ) FROM product_feature me WHERE ( feature = ? AND feature_id IS NULL AND ord = ? ): 'kdkdkdk', '2' INSERT INTO product_feature (feature, feature_id, ord) VALUES (?, ?, ?): 'kdkdkdk', 'NULL', '2' SELECT COUNT( * ) FROM product_feature me WHERE ( feature = ? AND feature_id IS NULL AND ord = ? ): 'jjjj', '3' INSERT INTO product_feature (feature, feature_id, ord) VALUES (?, ?, ?): 'jjjj', 'NULL', '3'

As you can see, we are not selecting product_id from product prior to putting features in. What should I do to avoid this problem? The documentation leads me to believe that create() should work for what I want, so I am guessing, I am doing something wrong.

In addition, why are there so many queries? What is count(*) being selected for and why are we doing one insert at a time instead of a bulk insert? Is that something I should improve on?

Thanks for your help!
Kate

_______________________________________________
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/[EMAIL PROTECTED]

Reply via email to