5
在下面這個例子:DBIx ::類例如
my $rs = $schema->resultset('CD')->search(
{
'artist.name' => 'Bob Marley'
'liner_notes.notes' => { 'like', '%some text%' },
},
{
join => [qw/ artist liner_notes /],
order_by => [qw/ artist.name /],
}
);
的DBIx cookbook說,這是將要生成的SQL:
# Equivalent SQL:
# SELECT cd.*, artist.*, liner_notes.* FROM cd
# JOIN artist ON cd.artist = artist.id
# JOIN liner_notes ON cd.id = liner_notes.cd
# WHERE artist.name = 'Bob Marley'
# ORDER BY artist.name
但是從菜譜的休息,我已經導致相信查詢只會選擇cd。*,除非當然使用預取像這樣:
my $rs = $schema->resultset('CD')->search(
{
'artist.name' => 'Bob Marley'
'liner_notes.notes' => { 'like', '%some text%' },
},
{
join => [qw/ artist liner_notes /],
order_by => [qw/ artist.name /],
prefetch => [qw/ artist liner_notes/],
}
);
下面是導致我相信這一點的說法:
[Prefetch] allows you to fetch results from related tables in advance
任何人都可以向我解釋我在這裏失蹤嗎?或不?非常感謝!
所以在上面的例子中,sql將被改爲「SELECT cd。*」? – srchulo
等效的sql - 沒錯 – stevenl