Created
December 10, 2014 12:25
-
-
Save nyaahara/0eb3d10e700a575ddf05 to your computer and use it in GitHub Desktop.
ActiveRecord:scopeをmergeする(引数も取れるよ!)
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 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