Perl DBIx::类示例

Perl DBIx::类示例,perl,orm,catalyst,dbix-class,Perl,Orm,Catalyst,Dbix Class,在下面的示例中: 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表示

在下面的示例中:

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表示将生成以下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与食谱的内容相矛盾,看起来像是一个错误

Join将在执行查询并应用筛选和排序条件时使用联接表中的列,但不会返回联接表的列。这意味着,如果您执行
$cd->artist->name
,则需要它执行另一个
选择artist.*FROM artist WHERE artist.id=?
,以便在每次调用该语句时获取艺术家的名称


预回迁也用于从预回迁表中选择所有列。当您实际需要这些列时,使用预回迁更为有效,例如,这样您就可以执行
$cd->artist->name
,而无需执行其他查询。但是,如果您不需要这些列,那么加载这些数据会带来不必要的性能损失。

因此,在上面的示例中,sql将更改为“SELECT cd.*”?