Skip to content

Commit

Permalink
move include work to an association includes
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorganIO authored and nickcharlton committed May 2, 2017
1 parent f7fd1b6 commit 16f184f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
10 changes: 1 addition & 9 deletions app/controllers/administrate/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,7 @@ def find_resource(param)
end

def resource_includes
association_classes = [
Administrate::Field::HasMany, Administrate::Field::HasOne,
Administrate::Field::BelongsTo
]

dashboard.class::ATTRIBUTE_TYPES.map do |key, value|
key if association_classes.include?(value) ||
association_classes.include?(value.try :deferred_class)
end.compact
dashboard.association_includes
end

def resource_params
Expand Down
11 changes: 11 additions & 0 deletions lib/administrate/base_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ def display_resource(resource)
"#{resource.class} ##{resource.id}"
end

def association_includes
association_classes = [Field::HasMany, Field::HasOne, Field::BelongsTo]

collection_attributes.map do |key|
field = self.class::ATTRIBUTE_TYPES[key]

next key if association_classes.include?(field)
key if association_classes.include?(field.try :deferred_class)
end.compact
end

private

def attribute_not_found_message(attr)
Expand Down

0 comments on commit 16f184f

Please sign in to comment.