@@ -45,7 +45,7 @@ def primary_key
45
45
end
46
46
47
47
def foreign_key
48
- return unless [ :embeds_one , :embeds_many ] . exclude? ( macro . to_sym )
48
+ return if embeds?
49
49
association . foreign_key . to_sym rescue nil
50
50
end
51
51
@@ -82,7 +82,7 @@ def read_only?
82
82
83
83
def nested_options
84
84
nested = nested_attributes_options . try { |o | o [ name ] }
85
- if !nested && [ :embeds_one , :embeds_many ] . include? ( macro . to_sym ) && !association . cyclic
85
+ if !nested && [ :embeds_one , :embeds_many ] . include? ( macro . to_sym ) && !cyclic?
86
86
raise <<-MSG . gsub ( /^\s +/ , '' )
87
87
Embbeded association without accepts_nested_attributes_for can't be handled by RailsAdmin,
88
88
because embedded model doesn't have top-level access.
@@ -96,13 +96,24 @@ def association?
96
96
true
97
97
end
98
98
99
+ def macro
100
+ association . try ( :macro ) || association . class . name . split ( '::' ) . last . underscore . to_sym
101
+ end
102
+
103
+ def embeds?
104
+ [ :embeds_one , :embeds_many ] . include? ( macro )
105
+ end
106
+
99
107
private
100
108
101
109
def inverse_of_field
102
110
association . respond_to? ( :inverse_of_field ) && association . inverse_of_field
103
111
end
104
112
105
- delegate :macro , :options , to : :association , prefix : false
113
+ def cyclic?
114
+ association . respond_to? ( :cyclic? ) ? association . cyclic? : association . cyclic
115
+ end
116
+
106
117
delegate :nested_attributes_options , to : :model , prefix : false
107
118
delegate :polymorphic_parents , to : RailsAdmin ::AbstractModel
108
119
end
0 commit comments