<div dir="ltr"><div>Hello,<br></div><div><br></div><div>Is there a solution for the following (quite repeating for me) problem? I have a table (customer) containing foreign key (address_id) to table address. The rows in address table are just values, they do not represent unique addresses. Two different customers have two different records (two different ids) in address table.</div><div><br></div><div>When I create customer together with address and pass the adress as hashref (which is very comfortable), the address resultset is first searched for the values passed and only if the address is not found, new address is created.</div><div><br></div><div>Is there a way to make DBIC skip the find and always create the related record (while passing related record as plain hashref)?</div><div><br></div><div>Thanks for any info</div><div><br></div><div>Roman </div><div><br></div><div><br></div><div># the tables (in SQLite are like)</div><div>create table customer (</div><div>   customer_id INTEGER PRIMARY KEY,</div><div>   name varchar(128) NOT NULL,</div><div>   address_id INTEGER NOT NULL</div><div>);</div><div><br></div><div>create table address (</div><div>   address_id INTEGER PRIMARY KEY,</div><div>   street varchar(128) NOT NULL,</div><div>   city varchar(128) NOT NULL</div><div>);</div><div><br></div><div># The schema is like</div><div>use common::sense;</div><div><br></div><div>{</div><div><br></div><div>    package MyApp::Schema::Result::Customer;</div><div>    use base qw/DBIx::Class::Core/;</div><div><br></div><div>    __PACKAGE__-&gt;table(&#39;customer&#39;);</div><div>    __PACKAGE__-&gt;add_columns(qw/ customer_id name address_id /);</div><div>    __PACKAGE__-&gt;set_primary_key(&#39;customer_id&#39;);</div><div>    __PACKAGE__-&gt;has_one(</div><div>        &#39;address&#39;,</div><div>        &#39;MyApp::Schema::Result::Address&#39;,</div><div>        { &#39;foreign.address_id&#39; =&gt; &#39;self.address_id&#39; }</div><div>    );</div><div><br></div><div>    package MyApp::Schema::Result::Address;</div><div>    use base qw/DBIx::Class::Core/;</div><div><br></div><div>    __PACKAGE__-&gt;table(&#39;address&#39;);</div><div>    __PACKAGE__-&gt;add_columns(qw/ address_id street city/);</div><div>    __PACKAGE__-&gt;set_primary_key(&#39;address_id&#39;);</div><div><br></div><div>    package MyApp::Schema;</div><div>    use base qw(DBIx::Class::Schema);</div><div><br></div><div>    __PACKAGE__-&gt;register_class( &#39;Customer&#39;,</div><div>        &#39;MyApp::Schema::Result::Customer&#39; );</div><div>    __PACKAGE__-&gt;register_class( &#39;Address&#39;, &#39;MyApp::Schema::Result::Address&#39; );</div><div>}</div><div><br></div><div>my $schema = MyApp::Schema-&gt;connect( &#39;dbi:SQLite:sample.db&#39;, &#39;&#39;, &#39;&#39; );</div><div>my ( $c1, $c2 ) = map {</div><div>    $schema-&gt;resultset(&#39;Customer&#39;)-&gt;create(</div><div>        {</div><div>            name    =&gt; $_,</div><div>            address =&gt; {</div><div>                street =&gt; &#39;Axmanova 11&#39;,</div><div>                city   =&gt; &#39;Brno&#39;,</div><div>            }</div><div>        }</div><div>      )</div><div>} &#39;Pavel Petr&#39;, &#39;Petr Pavel&#39;;</div><div><br></div><div>warn $c1-&gt;address_id == $c2-&gt;address_id? &quot;NOT OK&quot;: &quot;OK&quot;;</div><div><br></div></div>