can preloading use just a single query per table (even if referenced multiple times)

9 views
Skip to first unread message

Yavor Nikolov

unread,
May 1, 2014, 1:27:25 PM5/1/14
to rubyonra...@googlegroups.com
Hi,

Let's take a look at the following example:

Visitor.preload(
  {allowed_meals: [:meal]}
  {meal_availabilities: [:meal]}
)


What happens is that Rails (I'm using version 4.1) is issuing several queries to meals:

    Meals Load ... SELECT * from meals where id in (1, 2, 3, 4, 5) # using list of ids relevant for "allowed_meals"
    Meals Load ... SELECT * from meals where id in (3, 4, 5, 6) # using list of ids relevant for "meal_availabilities"


For performance reasons - it would be nice to issue just a single query instead of above two, e.g.:
    Meals Load ... SELECT * from meals where id in (1, 2, 3, 4, 5, 6)

Is that possible?

Regards,
Yavor
Reply all
Reply to author
Forward
0 new messages