Hi, everybody!
I am trying to figure out how to add a related model to an anonymous
scope to complete a search. Right now, I have this:
if request.post?
scope = Record.scoped({})
scope = scope.conditions “color = ?”, params[:color] unless
params[:color] == ‘–Select Color–’
scope = scope.conditions “size = ?”, params[:size] unless
params[:size] == ‘–Select Size–’
scope = scope.conditions “shape = ?”, params[:shape] unless
params[:shape] == ‘–Select Sample Rate–’
scope = scope.conditions “quantity = ?”, params[:quantity]
unless params[:quantity] == ‘–Select Quantity–’
scope = scope.conditions “file_short = ?”, params[:length]
unless params[:length] == ‘–Select Length–’
scope = scope.conditions “pair.run.widget = ?”, params[:widget]
unless params[:widget] == ‘–Select Name–’
@records = scope
end
Records belong to Pairs, and Pairs belong to Runs. Everything will
work fine unless a widget is selected, and I need to have it located,
at which point it returns a “No such column” from SQL. Is there a
work around to allow you to get to a related model?