Moose back on Track

Get back on track day here in the Moose-Pen

Well after mulling things over last night I think I will just have to make a note in my API that the 'view' fix will only work for the first layer of 'Link' and I will give a few examples of bets to use this feature and how to avoid problems.

Today I started on practical testing again with the plan being add in a new person/address record and then see if I get the correct values out.

Now to start I created two new Xtest::DA classes 'Address' and 'PeopleAddress' to work with and I instantiate all of these classes using the first record from some tests data I have in utils class;

my $dbh = $user_db->connect();
my $new_person = $user_db->new_person_data->[0];

my $person= Xtest::DA::Person->new({first_name=>$new_person->{first_name},
my $address= Xtest::DA::Address->new({ street=>$new_person->{street},

my $person_address= Xtest::DA::PeopleAddress->new({
people_id =>$new_person->{id},

and neat and good then I next go on to create a person, address and person_address utilizing the 'Database::Accessors' built into each of those classes;

my $da = $person->da();
ok($da->create($dbh,$person),"Create New User");
ok($da->result()->effected == 1,"One row effected");

$da = $address->da();
ok($da->create($dbh,$address),"Create New Address");
ok($da->result()->effected == 1,"One row effected");

$da = $person_address->da();

ok($da->create($dbh,$person_address),"Create New Person Address");
ok($da->result()->effected == 1,"One row effected");

now all the above worked lovely but when I tried to 'retrieve' the next record using the '$da' from the 'Person' class and a new condition;

$da = $person->da();  
                left => {
                    name => 'user_id',
                right     => { value => $new_person->{user_id }},
                operator  => '=',


I got an SQL errro 'ORA-00904: "COUNTRY"."COUNTRY_ID": invalid identifier'

Looking at the generated SQL the offending section was;

 JOIN country ON = <*>country.country_id 
and from my $da 'link definition' I have

 {type       => 'LEFT',
   to         => { name => 'country'},
  conditions => [{ left => { name => 'id',
                         view => 'country' },
                       right => { name => 'country_id',
                                        view => 'address'}}]
which is correct as it should result in

JOIN country ON = address.country_id 
so that is telling me I have a bug someplace in I think Database::Accessor as the entered 'view' is being overridden by the Link->to value.

Looking at the code there

if (ref($element) eq 'Database::Accessor::Element'){
unless ( $element->view() ) {
$element->view( $self->view->name() );
$element->view($alias )
if ($alias and $right);


I see that could not happen as will only trigger a name change is the view is not presents so this must be in my Driver::DBI code;

Poking about in there I think I found the problem and fixed it with this patch;

my $sql = $element->name;
my $view = $element->view;
$view = $self->view->alias()
if ($view eq $self->view->name() and $self->view->alias());
-- if ($in_view) {
++ if (!$view and $in_view) {
$view = $in_view->name();
$view = $in_view->alias()
if ($in_view->alias());

so it will only use the $in_view if there is no view to start. Now I run my code and I get all six of my tests to pass so I add in one more to test what came back on the retrieve and my set looks only half filled;

'set' => [ [ '5',
] ];

only the main table items are in the set even though the SQL runs there is something not right in the SQL or the data someplace.

Oh well something for my next post.


Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations