问题
I've put together the following query, which works as I expect it to:
stuff = @thing.children.find(
:all,
:joins => :other,
:conditions => {:others => {:another_id => some_id}},
:limit => my_limit,
:offset => my_offset,
)
However, queries of the form find(:all)
are deprecated. I have tried changing my query to the following form:
stuff = @thing.children.find(
:joins => :other,
:conditions => {:others => {:another_id => some_id}},
:limit => my_limit,
:offset => my_offset,
).all
but this throws a database error. What's the correct way to write this query?
回答1:
Short of rewriting it to Arel, you can simply, change the .find to .all, and remove the :all symbol like so:
stuff = @thing.children.all(
:joins => :other,
:conditions => {:others => {:another_id => some_id}},
:limit => my_limit,
:offset => my_offset,
)
来源:https://stackoverflow.com/questions/10721787/rails-active-record-find-with-join-limit-and-offset