Hi monnks

I'm trying to use populate to fill three tables at once, and getting invalid SQL. With two tables this works, but with three tables there's a missing IN. By adding some debug code to DBIx::Class::Storage::DBI I was able output the SQL, and this is what is being sent to _prepare_sth:

INSERT INTO scenes ( film, time, title) VALUES ( (SELECT me.title FROM movies me WHERE ( ( director (SELECT me.name FROM directors me WHERE ( name = ? )) AND title = ? ) )), ?, ? )
That looks like it should work if there were only an IN between the WHERE and director. Below is the perl I'm using to demonstrate the problem. Is this a known DBIC limitation, or am I creating the relations in the schema incorrectly?
package TestDB::Scene { use parent 'DBIx::Class::Core'; __PACKAGE__->table('scenes'); __PACKAGE__->add_columns(qw<title time description film>); __PACKAGE__->set_primary_key(qw<time>); }; package TestDB::Film { use parent 'DBIx::Class::Core'; __PACKAGE__->table('movies'); __PACKAGE__->add_columns(qw<title director>); __PACKAGE__->set_primary_key(qw<title>); __PACKAGE__->has_many( scenes => 'Scene' ); }; package TestDB::Director { use parent 'DBIx::Class::Core'; __PACKAGE__->table('directors'); __PACKAGE__->add_columns(qw<name>); __PACKAGE__->set_primary_key(qw<name>); __PACKAGE__->has_many( nasties => 'Film' ); }; package TestDB { use parent 'DBIx::Class::Schema'; __PACKAGE__->load_classes(qw<Film Director Scene>); }; package main { use Modern::Perl; main: { my $schema = deploy_new_to_temp_file(); my $rs = $schema->resultset('Director'); my @population = ( { name => "Lesly Tack", nasties => [ { title => 'Alligator', scenes => [ { title => '1st swamp pan', time => '05:36-12:01', }, ] } ] } ); $rs->populate( \@population ); } sub deploy_new_to_temp_file { my $schema = TestDB->connect('dbi:SQLite:dbname=test'); $schema->deploy( { add_drop_table => 1 } ); return $schema; } };

Thanks for any help



- Boldra

In reply to SQL Syntax error from recursive DBIx::Class populate by Boldra

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.