0

我整理了以下查询,它按我的预期工作:

  stuff = @thing.children.find(
    :all,
    :joins => :other,
    :conditions => {:others => {:another_id => some_id}},
    :limit => my_limit,
    :offset => my_offset,
  )

但是,find(:all)不推荐使用表单查询。我尝试将查询更改为以下形式:

  stuff = @thing.children.find(
    :joins => :other,
    :conditions => {:others => {:another_id => some_id}},
    :limit => my_limit,
    :offset => my_offset,
  ).all

但这会引发数据库错误。编写此查询的正确方法是什么?

4

1 回答 1

0

如果不将其重写为 Arel,您可以简单地将 .find 更改为 .all,然后删除 :all 符号,如下所示:

stuff = @thing.children.all(
  :joins => :other,
  :conditions => {:others => {:another_id => some_id}},
  :limit => my_limit,
  :offset => my_offset,
)
于 2012-05-23T15:15:18.830 回答