Skip to content

Instantly share code, notes, and snippets.

@drusepth
Last active August 2, 2019 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drusepth/6f1d6b24e1cb158a944e589df1c87c5f to your computer and use it in GitHub Desktop.
Save drusepth/6f1d6b24e1cb158a944e589df1c87c5f to your computer and use it in GitHub Desktop.
@linked_entities = []
Rails.application.config.content_types[:all].each do |content_type|
@linked_entities += @document.document_entities
.where(entity_type: content_type.name)
.where.not(entity_id: nil)
.includes(:entity, entity: [:universe, :user])
.includes(entity: Rails.application.config.content_relations.fetch(content_type.name, []).map do |relation, data|
content_type.instance_methods.include?(data[:with]) ? data[:with] : nil
end.compact)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment