ActiveRecord::QueryMethods::WhereChain

1.8k Views Asked by At

I'm using squeel and I'm getting a ActiveRecord::QueryMethods::WhereChain returned from a query rather than an ActiveRecord::AssociationRelation.

Query:

game.golfers.where{competitors.swing_golfer IS DISTINCT FROM TRUE}

Query that returns AssociationRelation

game.golfers.where{"competitors.swing_golfer IS DISTINCT FROM TRUE"}

Notice the quotes change the return type.

Models

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

Any idea what this ActiveRecord::QueryMethods::WhereChain is and how I can use it or avoid it?

  • ruby 2.0.0
  • rails 4.0
  • squeel 1.1.1
1

There are 1 best solutions below

0
On

Take a look at this article:

http://erniemiller.org/2013/10/07/activerecord-where-not-sane-true/

where Ernie says "Its sole purpose is to exist to expose a not method,.."

Basically it was designed so that you could modify the original condition with a call to .not(...) without having to duplicate it.