File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
lib/active_model_serializers/adapter/json_api Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ def data_for_one(association)
55
55
else
56
56
association . reflection . type . to_s
57
57
end
58
+ # TODO: probably return nil if association.object is nil?
58
59
ResourceIdentifier . for_type_with_id ( type , id , serializable_resource_options )
59
60
else
60
61
# TODO(BF): Process relationship without evaluating lazy_association
Original file line number Diff line number Diff line change @@ -35,6 +35,20 @@ def test_relationship_with_nil_model
35
35
assert_equal ( expected , actual )
36
36
end
37
37
38
+ def test_relationship_with_nil_model_and_belongs_to_id_on_self
39
+ ActiveModelSerializers . config . jsonapi_use_foreign_key_on_belongs_to_relationship = true
40
+
41
+ expected = { data : nil }
42
+
43
+ model_attributes = { blog : nil }
44
+ relationship_name = :blog
45
+ model = new_model ( model_attributes )
46
+ actual = build_serializer_and_serialize_relationship ( model , relationship_name ) do
47
+ belongs_to :blog
48
+ end
49
+ assert_equal ( expected , actual )
50
+ end
51
+
38
52
def test_relationship_with_data_array
39
53
expected = {
40
54
data : [
You can’t perform that action at this time.
0 commit comments