lib/onsi/model.rb in onsi-1.3.1 vs lib/onsi/model.rb in onsi-2.0.1
- old
+ new
@@ -202,10 +202,14 @@
@metadata.each_with_object({}) do |(key, block), meta|
meta[key.to_s] = object.instance_exec(&block)
end
end
+ def legacy_relationship_render!
+ @legacy_relationship_render = true
+ end
+
private
def render_relationship_entry(object, key, value, rels)
attr = value[:attr]
relationship = get_relationship_value(attr, object)
@@ -222,9 +226,33 @@
object.send("#{attr}_id")
end
end
def format_relationship(relationship, value)
+ if @legacy_relationship_render == true
+ return legacy_format_relationship(relationship, value)
+ end
+
+ case relationship
+ when Enumerable
+ if relationship.empty?
+ return []
+ end
+
+ relationship.map { |v| { 'type' => value[:type].to_s, 'id' => v.to_s } }
+ else
+ unless relationship.to_s.present?
+ return nil
+ end
+
+ {
+ 'type' => value[:type].to_s,
+ 'id' => relationship.to_s
+ }
+ end
+ end
+
+ def legacy_format_relationship(relationship, value)
case relationship
when Array
relationship.map { |v| { 'type' => value[:type].to_s, 'id' => v.to_s } }
else
{