【发布时间】:2012-04-09 06:58:48
【问题描述】:
所以我对数据库执行了一个查询,我有一个完整的对象数组:
@attachments = Job.find(1).attachments
现在我有一个对象数组,我不想执行另一个数据库查询,但我想根据Attachment 对象的file_type 过滤数组,这样我就可以获得@987654325 的列表@ 其中文件类型为'logo',然后是另一个attachments 列表,其中文件类型为'image'
类似这样的:
@logos = @attachments.where("file_type = ?", 'logo')
@images = @attachments.where("file_type = ?", 'image')
但在内存中而不是数据库查询中。
【问题讨论】:
-
似乎是
partition- example here 的一个很好的用例。
标签: ruby-on-rails activerecord