From: Andy Allan Date: Wed, 14 Mar 2018 07:24:16 +0000 (+0800) Subject: Ensure reports have an issue id and a user id X-Git-Tag: live~3562^2~26 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/3e5a4a14df070909ebbfb76add8caae230d0d31d Ensure reports have an issue id and a user id --- diff --git a/app/models/report.rb b/app/models/report.rb index 3507d699f..816b8a421 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -25,6 +25,8 @@ class Report < ActiveRecord::Base belongs_to :issue, :counter_cache => true belongs_to :user + validates :issue, :presence => true + validates :user, :presence => true validates :details, :presence => true validates :category, :presence => true diff --git a/db/migrate/20160822153055_create_issues_and_reports.rb b/db/migrate/20160822153055_create_issues_and_reports.rb index ce2374c31..cd0dc7a9f 100644 --- a/db/migrate/20160822153055_create_issues_and_reports.rb +++ b/db/migrate/20160822153055_create_issues_and_reports.rb @@ -21,8 +21,8 @@ class CreateIssuesAndReports < ActiveRecord::Migration[5.0] add_index :issues, :updated_by create_table :reports do |t| - t.integer :issue_id - t.integer :user_id + t.integer :issue_id, :null => false + t.integer :user_id, :null => false t.text :details, :null => false t.string :category, :null => false t.timestamps :null => false diff --git a/db/structure.sql b/db/structure.sql index eac2acaaf..e41b0834f 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1064,8 +1064,8 @@ CREATE TABLE relations ( CREATE TABLE reports ( id integer NOT NULL, - issue_id integer, - user_id integer, + issue_id integer NOT NULL, + user_id integer NOT NULL, details text NOT NULL, category character varying NOT NULL, created_at timestamp without time zone NOT NULL,