[Dbix-class] Bug with relationships on new objects.

Matt S Trout dbix-class at trout.me.uk
Fri Jan 25 06:52:35 GMT 2008


On Fri, Jan 25, 2008 at 12:41:55PM +1100, brett gardner wrote:
> Matt S Trout wrote:
> >Which is, as I said, nothing to do with new vs. inflate_result.
> >
> >If you pass 'col => undef' to new(), you get the fk = NULL.
> >
> >If you use the 'columns' resultset attr to restrict the col set to not
> >include the column, you get the 'column does not exist'[0] behaviour.
> >
> >But all this is academic; if !has_column_loaded we should just be throwing
> >an exception, not creating the resultset anyway.
> >
> >Who fancies having a go at a patch? :)
> >
> >[0] which you call 'column is not set', which is almost accurate but not
> >quite :)
> >
> >  
> Right, well I wrote a patch (attached) that fixes the problem, but then 

Your patch seems to single out only the primary key, so you only fix
half the problem.

Why are you restricting it to this when any non-existant key column can
cause the exact same bug?

> running the test harness showed a problem as it breaks the behaviour.
> 
> my $artist = $schema->resultset('Artist')->create({
>    name=>'foo',
>    cds=>[
>     {title=>'foo',year=>2000},
>     {title=>'bar',year=>2000},
>    ]
> );
> 
> The "new" method in "Row.pm" creates a new "Artist" and calls 
> "new_related" for each of the "cds". Then when "insert" is called on the 
> "Artist", it updates the related objects' "artistid" column and calls 
> "insert" on each related object.
> 
> So the patch breaks this behaviour.

That code should do $self->result_source->related_source($rel)->resultset->new
instead.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list