我正在使用squeel
,我从查询而不是ActiveRecord::QueryMethods::WhereChain
返回ActiveRecord::AssociationRelation
。
查询:
game.golfers.where{competitors.swing_golfer IS DISTINCT FROM TRUE}
返回AssociationRelation
game.golfers.where{"competitors.swing_golfer IS DISTINCT FROM TRUE"}
请注意,引号会更改返回类型。
模型
class Game < ActiveRecord::Base
has_many :competitors
has_many :golfers, through: :competitors
end
class Golfer < ActiveRecord::Base
has_many :competitors
has_many :games, through: :competitors
end
知道这个ActiveRecord::QueryMethods::WhereChain
是什么以及如何使用或避免它?
答案 0 :(得分:0)
看一下这篇文章:
http://erniemiller.org/2013/10/07/activerecord-where-not-sane-true/
其中Ernie说“其唯一的目的是存在暴露非方法,......”
基本上它的设计是为了你可以通过调用.not(...)修改原始条件,而不必复制它。