Skip to content

Commit

Permalink
Use foreign_key
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorz-jakubiak committed Jan 28, 2020
1 parent 90538e9 commit 38c227a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/active_admin/mongoid/association/relatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ def macro
def embeds?
[:embeds_one, :embeds_many].include?(macro)
end

def foreign_key
return if embeds?
foreign_key.to_sym rescue nil
end
end
2 changes: 1 addition & 1 deletion lib/active_admin/mongoid/filters/resource_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def default_association_filters
without_embedded = resource_class.reflect_on_all_associations.reject { |e| e.embeds? }
poly, not_poly = without_embedded.partition{ |r| r.macro == :belongs_to && r.options[:polymorphic] }

filters = poly.map(&:foreign_type) + not_poly.map(&:name)
filters = poly.map(&:foreign_key) + not_poly.map(&:name)
filters.map &:to_sym
else
[]
Expand Down

0 comments on commit 38c227a

Please sign in to comment.