diff --git a/app/graph/types/claim_description_type.rb b/app/graph/types/claim_description_type.rb index 7468b3f44a..df35cdbf61 100644 --- a/app/graph/types/claim_description_type.rb +++ b/app/graph/types/claim_description_type.rb @@ -8,6 +8,7 @@ class ClaimDescriptionType < DefaultObject field :context, GraphQL::Types::String, null: true, resolver_method: :claim_context field :user, UserType, null: true field :project_media, ProjectMediaType, null: true + field :project_media_was, ProjectMediaType, null: true field :fact_check, FactCheckType, null: true do argument :report_status, GraphQL::Types::String, required: false, camelize: false end diff --git a/app/models/claim_description.rb b/app/models/claim_description.rb index 70a7287a67..048f72a4d5 100644 --- a/app/models/claim_description.rb +++ b/app/models/claim_description.rb @@ -38,6 +38,10 @@ def article_elasticsearch_data(action = 'create_or_update') self.index_in_elasticsearch(data) end + def project_media_was + ProjectMedia.find_by_id(self.project_media_id_before_last_save) + end + private def set_team diff --git a/lib/relay.idl b/lib/relay.idl index 198df43b56..44b7fc4d72 100644 --- a/lib/relay.idl +++ b/lib/relay.idl @@ -728,6 +728,7 @@ type ClaimDescription implements Node { id: ID! permissions: String project_media: ProjectMedia + project_media_was: ProjectMedia updated_at: String user: User } diff --git a/public/relay.json b/public/relay.json index e527c4df91..6d2bca582f 100644 --- a/public/relay.json +++ b/public/relay.json @@ -3696,6 +3696,20 @@ "isDeprecated": false, "deprecationReason": null }, + { + "name": "project_media_was", + "description": null, + "args": [ + + ], + "type": { + "kind": "OBJECT", + "name": "ProjectMedia", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, { "name": "updated_at", "description": null, diff --git a/test/models/claim_description_test.rb b/test/models/claim_description_test.rb index 722800404b..16048ddafc 100644 --- a/test/models/claim_description_test.rb +++ b/test/models/claim_description_test.rb @@ -165,4 +165,12 @@ def setup assert_equal 'paused', fc.reload.report_status assert_equal 'paused', pm.report_status(true) end + + test "should get information from removed item" do + pm = create_project_media + cd = create_claim_description project_media: pm + cd.project_media = nil + cd.save! + assert_equal pm, cd.project_media_was + end end