我使用的是squeel,我得到的是查询而不是ActiveRecord::AssociationRelation返回的ActiveRecord::QueryMethods::WhereChain。
查询:
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是什么吗?我如何使用它或避免它?
发布于 2014-02-18 00:56:38
看看这篇文章:
http://erniemiller.org/2013/10/07/activerecord-where-not-sane-true/
厄尼说:“它的唯一目的是暴露一个不存在的方法,.”
基本上,它的设计使得您可以通过调用.not(.)来修改原始条件。而不必重复。
https://stackoverflow.com/questions/20726110
复制相似问题