Skip to content

Instantly share code, notes, and snippets.

@bessey
Created July 30, 2013 11:32
Show Gist options
  • Save bessey/6112171 to your computer and use it in GitHub Desktop.
Save bessey/6112171 to your computer and use it in GitHub Desktop.
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