Difference between join and prefetch in DBIx::Class

时间:2018-07-03 17:23:26

标签: perl join dbix-class prefetch perl5

Please explain in details the difference between join and prefetch in DBIx::Class.

joins maps to JOIN in SQL, right?

prefetch makes to read all data from related tables, right?

But it seems for me that in the case of a has_a relationship to a table, joining and prefetching this table do exactly the same thing, add an SQL JOIN. Right? Is there any difference between join and prefetch for has_a relationships?

So when to use either (especially for has_a relationships)?

1 个答案:

答案 0 :(得分:1)

Prefetch是用于连接+选择的工具,并使用相关的结果对象填充缓存,因此在调用关系访问器方法时不会触发SQL查询。