[Dbix-class] Wrong table prefetched in diamond construct?
Gerhard Heift
ml-dbix-class-20090107-b968 at gheift.de
Sun May 3 23:06:10 GMT 2009
Hello,
I have a layout, which is like this:
Subject --> rel_a
| |
V V
rel_b --> object
subject contains only one row with 'blub'
object contains two rows, 'foo' and 'bar'
rel_a connects 'blub' to 'foo'
rel_b connects 'blub' to 'bar'
now I want to create a statement like this:
SELECT subject.*, object_b.* FROM subject
JOIN rel_a ON (subject.title = rel_a.title)
JOIN object object_a ON (rel_a.obj = object_a.title)
JOIN rel_b ON (subject.title = rel_b.title)
JOIN object object_b ON (rel_b.obj = object_b.title)
WHERE object_a.title = 'foo';
My first try was this [1]:
my $s = S->connect('dbi:SQLite:diamond.db');
foreach ($s->resultset('subject')
->search({
'object.title' => 'foo'
}, {
join => {
rel_a => 'object'
}
})
->search(undef, {
prefetch => {
rel_b => 'object'
}
})->all()
) {
# should return bar, but it returns foo
print $_->rel_b->first->object->title, "\n";
}
Did I do something wrong?
Thanks,
Gerhard
[1] http://gist.github.com/106183
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
Url : http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20090504/b898c845/attachment.pgp
More information about the DBIx-Class
mailing list