Skip to content

Instantly share code, notes, and snippets.

@apeiros
Created January 13, 2018 18:45
Show Gist options
  • Save apeiros/71d13b09e01a333071bc3dfdee9f1845 to your computer and use it in GitHub Desktop.
Save apeiros/71d13b09e01a333071bc3dfdee9f1845 to your computer and use it in GitHub Desktop.
recurse_relation = ->(model, relation, &block) {
model.public_send(relation).each do |descendant|
block.call(descendant)
recurse_relation.call(descendant, relation, &block)
end
}
recurse_relation.call(YourModel.find(id), :your_relation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment