Rails 4 Query on Association using Includes

This works:

Model1.includes(:model2 => :model2).where(model2s: {order: 2})

How would I write a query for order <= 2?

What I would really like to write is:

Model1.includes(:model2 => :model2).where(“model2s.order <= 2”)

This worked in Rails 3, I would like to build up the where clause as a
string. Any ideas on how I can use a string to query an association in
Rails 4 would be much appreciated.

Many thanks,

Mike

You can also use:

Model1.includes(:model2 => :model3).where(“model2s.order <=
2”).references(:model2 => :model3)

I never worked this out, but you can use joins instead of includes as a
work around.