Skip to content

Instantly share code, notes, and snippets.

@bcurren
Created March 14, 2011 23:04
Show Gist options
  • Save bcurren/870047 to your computer and use it in GitHub Desktop.
Save bcurren/870047 to your computer and use it in GitHub Desktop.
class Model < ActiveRecord::Base
default_scope order("title desc")
scope :with_city, lambda { |city| where("city = ?", city) }
def self.search
# How do I do this? Need to remove a relation
self.scoped.remove(self.default_scoping).all
end
end
Model.with_city('San Francisco').search # What I want -> select * from models where city = 'San Francisco'
class Model < ActiveRecord::Base
default_scope order("title desc")
scope :with_city, lambda { |city| where("city = ?", city) }
def self.search
self.unscoped.all
end
end
Model.with_city('San Francisco').search # Not what I want -> select * from model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment