Skip to content

Instantly share code, notes, and snippets.

@logrusorgru
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save logrusorgru/23f67ed331d13a4ebfae to your computer and use it in GitHub Desktop.
Save logrusorgru/23f67ed331d13a4ebfae to your computer and use it in GitHub Desktop.
Rails 3 to Rails 4 => lambda instead of conditions

Rails 3

has_many  :active_events, :through => :event_users, 
          :class_name => "Event", 
          :source => :event, 
          :conditions => ['event_users.active = ?',true]

Rails 4

has_many :active_events, through: :event_users,
         class_name: 'Event',
         source: :event,
         -> { where event_users: { active: true } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment