Skip to content

Instantly share code, notes, and snippets.

@derwiki
Created March 10, 2016 17:04
Show Gist options
  • Select an option

  • Save derwiki/f0c7214eff7d872c1176 to your computer and use it in GitHub Desktop.

Select an option

Save derwiki/f0c7214eff7d872c1176 to your computer and use it in GitHub Desktop.
Overriding `default_scope` in `has_many` `through` association.
class Website < ActiveRecord::Base
default_scope { where.not(is_private: true) }
end
class WebsiteScreenshot < ActiveRecord::Base
Website.unscope(where: :is_private) do
belongs_to :website
has_many :website_follows, through: :website
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment