Skip to content

Instantly share code, notes, and snippets.

@puneetpandey
Created November 27, 2014 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save puneetpandey/25de4fd04a82ad0937a6 to your computer and use it in GitHub Desktop.
Save puneetpandey/25de4fd04a82ad0937a6 to your computer and use it in GitHub Desktop.
class Product < ActiveRecord::Base
has_many :suppliers, conditions: ["suppliers.status = ?", true]
end
# In Rails4, if you wish to use the same, you can use the below syntax:
class Product < ActiveRecord::Base
has_many :suppliers, -> { where("suppliers.status = ?", true) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment