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)
5555 else
5656 association . reflection . type . to_s
5757 end
58+ # TODO: probably return nil if association.object is nil?
5859 ResourceIdentifier . for_type_with_id ( type , id , serializable_resource_options )
5960 else
6061 # 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
3535 assert_equal ( expected , actual )
3636 end
3737
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+
3852 def test_relationship_with_data_array
3953 expected = {
4054 data : [
You can’t perform that action at this time.
0 commit comments