[Dbix-class] Bug? Failing test case for joining on default values

J. Shirley jshirley at gmail.com
Tue Nov 18 17:16:20 GMT 2008


My previous email was just the symptom, and after simplifying it I
found the core problem.  Sometime since 0.08010 and trunk, behavior
changed on the handling of default values after an object is inserted.
The previous behavior wasn't actually correct, but my test case wasn't
comprehensive enough yet to show the bug that was present in 0.08010.

Imagine a single table that relates to itself with a default value
('name') that is part of the join condition (the full schema is in the
attached patch).  Unless you specifically define the default value,
DBIC trunk fails.  Here is a simplified example:

With a relation defined like this:
__PACKAGE__->has_many('selves', 'DBICTest::Schema::DefaultJoin',
    {
        'foreign.joinid' =3D> 'self.joinid',
        'foreign.name'   =3D> 'self.name' # name has a default_value set
    }
);


my $obj_1 =3D $schema->resultset("DefaultJoin")->create({ joinid =3D> "1" }=
);
my $obj_2 =3D $schema->resultset("DefaultJoin")->create({ joinid =3D> "1" }=
);
$obj_1->selves;

# Fails with: DBICTest::Schema::DefaultJoin::selves(): Column name not
loaded on DBICTest::DefaultJoin=3DHASH(0xb72e64) trying to resolve
relationship at t/join_on_default_value.t line 20

Now, this behavior is better than 0.08010 -- which just does the join
without including 'name' at all in the relationship.  The query is
simply:
   SELECT COUNT( * ) FROM self_join me WHERE ( me.joinid =3D ? ): '1'

If I assign 'name' the query and behavior (in both 0.08010 and trunk)
is correct.

The solution that I have now is to refetch via ->discard_changes and
that solves the underlying problem.  I'm somewhat at a loss on what
the proper way to solve it is, as the best idea is that when an object
is defined inspect if a join condition is a default value and if so,
automatically call ->discard_changes on the row after insert?

Well, the first step is a failing test case, right?  It's attached,
and let me know if you want me to commit.

-J
-------------- next part --------------
A non-text attachment was scrubbed...
Name: join_on_default.patch
Type: application/octet-stream
Size: 2492 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20081118/c6=
5a440e/join_on_default.obj


More information about the DBIx-Class mailing list