title: DBIx::Class insert has many
body: <p>I'm using <a href="https://metacpan.org/pod/DBIx::Class" rel="nofollow">DBIx::Class</a> and I have two Schemas:</p>
  
  <pre><code>use utf8;
  package MyApp::Schema::Result::Person;
  
  use Moose;
  use MooseX::NonMoose;
  use MooseX::MarkAsMethods autoclean =&gt; 1;
  extends 'DBIx::Class::Core';
  
  __PACKAGE__-&gt;table("person");
  
  __PACKAGE__-&gt;add_columns(
      "id",
       { data_type =&gt; "integer", is_auto_increment =&gt; 1, is_nullable =&gt; 0 },
  );
  
  __PACKAGE__-&gt;has_many(
      "addresses",
      "MyApp::Schema::Result::Address",
      { "foreign.person_id" =&gt; "self.id" },
      { cascade_copy =&gt; 0, cascade_delete =&gt; 0 },
  );
  
  1;
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>use utf8;
  package MyApp::Schema::Result::Address;
  
  use Moose;
  use MooseX::NonMoose;
  use MooseX::MarkAsMethods autoclean =&gt; 1;
  extends 'DBIx::Class::Core';
  
  __PACKAGE__-&gt;table("address");
  
  __PACKAGE__-&gt;add_columns(
      "id",
       { data_type =&gt; "integer", is_auto_increment =&gt; 1, is_nullable =&gt; 0 },
       "person_id",
       { data_type =&gt; "integer", is_foreign_key =&gt; 1, is_nullable =&gt; 1 },
  );
  
  __PACKAGE__-&gt;belongs_to(
      "person",
       "MyApp::Schema::Result::Person",
       { id =&gt; "person_id" },
       {  
           is_deferrable =&gt; 0,
           join_type     =&gt; "LEFT",
           on_delete     =&gt; "NO ACTION",
           on_update     =&gt; "NO ACTION",
       },  
  );
  
  1;
  </code></pre>
  
  <p>What I am trying to do is add multiple addresses at once with a person object. I am doing that like so:</p>
  
  <pre><code>my $person = $c-&gt;model('DB::Person')-&gt;new_result({});
  $person-&gt;addresses([
      {
          id =&gt; 1,
          person_id =&gt; 1,
      },
      {
          id =&gt; 2,
          person_id =&gt; 1,
      },
  ]);
  
  $person-&gt;insert;
  </code></pre>
  
  <p>I followed this format from this <a href="http://www.catalystframework.org/calendar/2009/17" rel="nofollow">article</a>, but it doesn't seem to work. Only the person row gets inserted, but the addresses associated with it do not. I've also tried setting <code>addresses</code> to an arrayref of <code>MyApp::Schema::Result::Address</code> objects before inserting, but that doesn't work either. Does anyone know what I'm doing wrong? I don't get any errors, it just doesn't insert the addresses. In the article they use create instead of insert. Is it because of this? If so, is there a way to do this using <a href="https://metacpan.org/pod/DBIx::Class::Row#insert" rel="nofollow">insert</a> or <a href="https://metacpan.org/pod/DBIx::Class::Row#update" rel="nofollow">update</a>?</p>