Skip to content

Instantly share code, notes, and snippets.

@maxcal
Created November 15, 2015 04:12
Show Gist options
  • Select an option

  • Save maxcal/254aaa3cc790d1b8fda0 to your computer and use it in GitHub Desktop.

Select an option

Save maxcal/254aaa3cc790d1b8fda0 to your computer and use it in GitHub Desktop.
class Parent < ActiveRecord::Base
has_many :children
has_many :skills, through: :children
def self.with_skill(skill_type)
eager_load(:skills, :children).map do |p|
p.children = [] unless p.skills.any? { |s| s.skill_type = skill_type }
p
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment