Created
July 30, 2013 11:32
-
-
Save bessey/6112171 to your computer and use it in GitHub Desktop.
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 :children | |
end | |
class Child < ActiveRecord::Base | |
has_one :parent | |
has_many :sub_children | |
def self.method | |
# I want this to have a conditional .where("child.parent_id" => parent_id) if I called .method via the parent model, | |
# as if it were a nested scope. | |
SubChildren.joins(:child).sum(....) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment