Skip Menu |

This queue is for tickets about the Tangram CPAN distribution.

Report information
The Basics
Id: 22696
Status: resolved
Worked: 3 hours (180 min)
Priority: 0/
Queue: Tangram

People
Owner: Nobody in particular
Requestors: MLAWREN [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in:
  • 2.09
  • 2.10
Fixed in: (no value)



Subject: [REGRESSION] 'back' foreign key doesn't fully inflate object
The current git tree fails to fully inflate objects that are reached via the 'back' field defined in an 'iset'. Take the following schema: Hat => { fields => { string => [ qw( colour ) ], }, }, NaturalPerson => { fields => { string => [ qw( firstName name ) ], int => [ qw( age ) ], ref => { partner => { null => 1 } }, iset => { hats => { class => 'Hat', back => 'owner', }, }, }, }, If you $storage->select a 'Hat' you can reach the 'owner'. However the owner's 'hats' array/Set::Object list is empty. The other fields are good. This applies not just to hats but any other mapping that existed for the class. I know that this behaviour doesn't exist in 2.08 but don't know where between 2.08 and git it broke. Test to follow.
Test attached.
#!/usr/bin/perl use strict; use warnings; use Test::More tests => 10; BEGIN { use_ok('Tangram'); use_ok('Class::Tangram::Generator'); }; my $schemahash = { classes => { Hat => { fields => { string => [ qw( colour ) ], }, }, NaturalPerson => { fields => { string => [ qw( firstName name ) ], int => [ qw( age ) ], ref => { partner => { null => 1 } }, iset => { hats => { class => 'Hat', back => 'owner', }, }, }, }, } }; my $schema = Tangram::Schema->new($schemahash); my $file = "/tmp/tangram$$.db"; my @cp = ("dbi:SQLite:$file"); unlink($file); Tangram::Relational->deploy($schema, @cp); my $gen = Class::Tangram::Generator->new($schema); my $storage = Tangram::Relational->connect($schema, @cp); my $hat = $gen->new('Hat', colour => 'blue'); my $person = $gen->new('NaturalPerson', name => 'tangram'); $person->hats->insert($hat); ok(scalar $person->hats, 'hat given to owner'); $storage->insert($person); undef $person; undef $hat; ($person) = $storage->select('NaturalPerson'); ok(ref($person) eq 'NaturalPerson', 'person inserted and retrieved'); ($hat) = $person->hats; ok(ref($hat) eq 'Hat', 'person has a hat'); (my $owner) = $hat->owner; ok(ref($owner) eq 'NaturalPerson', 'owner of hat is a person'); ok(@{$owner->hats}, 'owner of hat has hats'); my $rem = $storage->remote('Hat'); ($hat) = $storage->select($rem, $rem->{owner} eq $person); ok(ref($hat) eq 'Hat', 'hat inserted and retrieved'); ($owner) = $hat->owner; ok(ref($owner) eq 'NaturalPerson', 'owner of hat is a person'); ok(@{$owner->hats}, 'owner of hat has hats');
From: MLAWREN [...] cpan.org
Show quoted text
> I know that this behaviour doesn't exist in 2.08 but don't know where > between 2.08 and git it broke. Test to follow.
Test script fails for version 2.10.
From: SAMV [...] cpan.org
ok, I see what's happening. I have committed a fix and commentary to http://utsl.gen.nz/gitweb/?p=Tangram;a=commit;h=36e28bfa On Mon Oct 30 09:23:32 2006, MLAWREN wrote: Show quoted text
> The current git tree fails to fully inflate objects that are reached via > the 'back' field defined in an 'iset'. Take the following schema: > > Hat => { > fields => { > string => [ qw( colour ) ], > }, > }, > NaturalPerson => { > fields => { > string => [ qw( firstName name ) ], > int => [ qw( age ) ], > ref => { partner => { null => 1 } }, > iset => { > hats => { > class => 'Hat', > back => 'owner', > }, > }, > }, > }, > > If you $storage->select a 'Hat' you can reach the 'owner'. However the > owner's 'hats' array/Set::Object list is empty. The other fields are good. > This applies not just to hats but any other mapping that existed for the > class. > > I know that this behaviour doesn't exist in 2.08 but don't know where > between 2.08 and git it broke. Test to follow.