Still Buggy Moose
Fix a little bug day here in the Moose-pen
One of the great things of tests based development is you are always finding new bugs as you progress. Yesterday I found yet another;
Given this link/join
links => {
type => 'LEFT',
to => { name => 'address',
alias=> 'test' },
conditions => [
{
left => { name => 'id' },
right => {
name => 'user_id',
alias=> 'test',
}
}
]
},
I was still getting this error
Expected LEFT JOIN address test ON people.id = test.user_id
Generated LEFT JOIN address test ON people.id = address.user_id
the 'alias' for that join was just not getting set correctly.
The first thing I did to debug this test was to figure out exactly where was this error starting with Database::Accessor and then passed in to Driver::DBI or was the but in Driver::DBI itself.
To figure out where the error was I first looked into the 'links' attribute of the Database::Accessor that was being generated for the above 'Link/Join'. A dump of the appropriate part;
...
'predicates' => bless( {
'left' => bless( {
'name' => 'id'
}, 'Database::Accessor::Element' ),
'right' => bless( {
'name' => 'user_id',
'alias' => 'test'
}, 'Database::Accessor::Element' ),
'close_parentheses' => 0,
…
I see that the correct 'alias' is found in the Database::Accessor. How about in the Driver::DBI;
'predicates' => bless( {
'operator' => '=',
'left' => bless( {
'view' => 'people',
'name' => 'id'
}, 'Database::Accessor::Element' ),
'right' => bless( {
'view' => 'address',
'name' => 'user_id',
'alias' => 'test'
}, 'Database::Accessor::Element' ),
'close_parentheses' => 0,
Now in this case what I think I see here is a mistake in how I am calling my API in the test;
right => {
name => 'user_id',
alias=> 'test',
}.
That alias is the alias of the 'element/field' not the alias of the view. So my code is correctly filling in 'address' as the view as that is the view of the 'Link/Join'.
A quick change to my test;
right => {
name => 'user_id',
-- alias=> 'test',
++ view=> 'test',
}
and test 11 now passes
...
ok 10 - Left Link with 1 condition and alias create params correct
ok 11 - Left Link with 1 condition and alias retrieve SQL correct
ok 12 - Left Link with 1 condition and alias retrieve params correct
…
Now that solves that little problem. It does leave one with a bigger question should I tighten up the validation on a 'Link/Join' so I will have to add a view at all times and drop any pretense of filling in the view automatically.
I guess a post for later.
Leave a comment