File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
app/serializers/forest_liana Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -131,6 +131,33 @@ def relationship_related_link(attribute_name)
131131 ret
132132 end
133133
134+ def has_one_relationships
135+ return { } if self . class . to_one_associations . nil?
136+ data = { }
137+ self . class . to_one_associations . each do |attribute_name , attr_data |
138+ relation = object . class . reflect_on_all_associations . find { |a | a . name == attribute_name }
139+ next if !should_include_attr? ( attribute_name , attr_data )
140+
141+ if relation && relation . belongs_to? && relation . polymorphic? . nil?
142+ reflection_primary_key = relation . options [ :primary_key ] &.to_sym || :id
143+ klass_primary_key = relation . klass . primary_key . to_sym
144+
145+ if reflection_primary_key != klass_primary_key
146+ data [ attribute_name ] = attr_data . merge ( {
147+ attr_or_block : proc {
148+ relation . klass . find_by ( reflection_primary_key => object . send ( relation . foreign_key ) )
149+ }
150+ } )
151+ next
152+ end
153+ end
154+
155+ data [ attribute_name ] = attr_data
156+ end
157+
158+ data
159+ end
160+
134161 private
135162
136163 def intercom_integration?
You can’t perform that action at this time.
0 commit comments