Skip to content

Instantly share code, notes, and snippets.

@nyaahara
Created December 10, 2014 12:25
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 nyaahara/0eb3d10e700a575ddf05 to your computer and use it in GitHub Desktop.
Save nyaahara/0eb3d10e700a575ddf05 to your computer and use it in GitHub Desktop.
ActiveRecord:scopeをmergeする(引数も取れるよ!)
class Parent << ActiveRecord::Base
has_many :childs
end
class Child << ActiveRecord::Base
belong_to :parent
scope :hoge_is_true, ->(args){ where(hoge: :true).where(hage: :args) }
end
Parent.includes(:childs).references(:childs).merge(Child.hoge_is_true(1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment