导轨包括与选择 [英] rails include with options
本文介绍了导轨包括与选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能限制一个AR:包括说只拉一个记录...
Is it possible to limit an AR :include to say only pull in one record...
Item.find(:all,
:include => [ :external_ratings, :photos => LIMIT 1 ])
予有项目的列表和每个项目具有介于5和15的照片。我想加载照片的身份证到内存中,但我并不需要所有的人,我只是想preVIEW第一个。
I have a list of items and each item has between 5 and 15 photos. I want to load a photo id into memory, but i don't need all of them, I just want to preview the first one.
有没有办法做到这一点?
Is there a way to do this?
推荐答案
我不打算去调查详细的查询,但我想的find_by_sql
是为了针对这种特殊情况下。
I'm not going to investigate the detailed query, but I'm thinking find_by_sql
is in order for this particular case.
这篇关于导轨包括与选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文