Created
August 4, 2014 19:32
-
-
Save ollieglass/00d029c866aa0a70bf26 to your computer and use it in GitHub Desktop.
Imagine I have tickets that belong to events. As a developer, I only want to access tickets that belong to an event, and I want to safeguard against accessing all tickets (contrived example, but anyway). If event ids start at 0, and I set the default scope to an event_id of -1, then if I forget to set an event (which would select all tickets), I…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Ticket < ActiveRecord::Base | |
belongs_to :event | |
default_scope where(event_id: -1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment