Skip to content

Commit 319cbd3

Browse files
fix non resource associations
1 parent 7c483e7 commit 319cbd3

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

lib/plutonium/core/actions/basic_action.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def initialize(*args, **kwargs)
99

1010
private
1111

12-
def action_options = {}.freeze
12+
def action_options = {}
1313
end
1414
end
1515
end

lib/plutonium/core/fields/renderers.rb

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def self.infer_for_resource_attribute(resource_class, attr_name, **options)
2121

2222
if (reflection = resource_class.try(:reflect_on_association, attr_name))
2323
type = reflection.macro
24+
options[:reflection] = reflection
2425
elsif (attachment = resource_class.try(:reflect_on_association, :"#{attr_name}_attachment"))
2526
type = :attachment
2627
elsif (column = resource_class.try(:column_for_attribute, attr_name))

lib/plutonium/core/fields/renderers/association_renderer.rb

+13-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@ module Core
33
module Fields
44
module Renderers
55
class AssociationRenderer < BasicRenderer
6+
attr_reader :reflection
7+
8+
def initialize(name, reflection:, **user_options)
9+
@reflection = reflection
10+
super(name, **user_options)
11+
end
12+
613
private
714

8-
def renderer_options = {helper: :display_association_value}.freeze
15+
def renderer_options
16+
resource_record = reflection.klass.include? Plutonium::Reactor::ResourceRecord
17+
{
18+
helper: resource_record ? :display_association_value : :display_name_of
19+
}
20+
end
921
end
1022
end
1123
end

lib/plutonium/core/fields/renderers/basic_renderer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def options = @options ||= renderer_options.deep_merge(@user_options)
1919

2020
private
2121

22-
def renderer_options = {}.freeze
22+
def renderer_options = {}
2323

2424
end
2525
end

0 commit comments

Comments
 (0)