Use a simple user_id for tables with one owning user
This is the standard way of naming in rails, and it avoids having to tell rails which models are actually required.
This commit is contained in:
parent
1d24228a3b
commit
1956ab5913
4 changed files with 49 additions and 49 deletions
|
@ -2,27 +2,27 @@
|
|||
#
|
||||
# Table name: issue_comments
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# issue_id :integer not null
|
||||
# commenter_user_id :integer not null
|
||||
# body :text not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# id :integer not null, primary key
|
||||
# issue_id :integer not null
|
||||
# user_id :integer not null
|
||||
# body :text not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_issue_comments_on_commenter_user_id (commenter_user_id)
|
||||
# index_issue_comments_on_issue_id (issue_id)
|
||||
# index_issue_comments_on_issue_id (issue_id)
|
||||
# index_issue_comments_on_user_id (user_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# issue_comments_commenter_user_id (commenter_user_id => users.id) ON DELETE => cascade
|
||||
# issue_comments_issue_id_fkey (issue_id => issues.id) ON DELETE => cascade
|
||||
# issue_comments_issue_id_fkey (issue_id => issues.id) ON DELETE => cascade
|
||||
# issue_comments_user_id (user_id => users.id) ON DELETE => cascade
|
||||
#
|
||||
|
||||
class IssueComment < ActiveRecord::Base
|
||||
belongs_to :issue
|
||||
belongs_to :user, :class_name => "User", :foreign_key => :commenter_user_id
|
||||
belongs_to :user
|
||||
|
||||
validates :body, :presence => true
|
||||
validates :user, :presence => true
|
||||
|
|
|
@ -2,27 +2,27 @@
|
|||
#
|
||||
# Table name: reports
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# issue_id :integer
|
||||
# reporter_user_id :integer
|
||||
# details :text not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# id :integer not null, primary key
|
||||
# issue_id :integer
|
||||
# user_id :integer
|
||||
# details :text not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_reports_on_issue_id (issue_id)
|
||||
# index_reports_on_reporter_user_id (reporter_user_id)
|
||||
# index_reports_on_issue_id (issue_id)
|
||||
# index_reports_on_user_id (user_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# reports_issue_id_fkey (issue_id => issues.id) ON DELETE => cascade
|
||||
# reports_reporter_user_id_fkey (reporter_user_id => users.id) ON DELETE => cascade
|
||||
# reports_issue_id_fkey (issue_id => issues.id) ON DELETE => cascade
|
||||
# reports_user_id_fkey (user_id => users.id) ON DELETE => cascade
|
||||
#
|
||||
|
||||
class Report < ActiveRecord::Base
|
||||
belongs_to :issue, :counter_cache => true
|
||||
belongs_to :user, :class_name => "User", :foreign_key => :reporter_user_id
|
||||
belongs_to :user
|
||||
|
||||
validates :details, :presence => true
|
||||
end
|
||||
|
|
|
@ -22,28 +22,28 @@ class CreateIssuesAndReports < ActiveRecord::Migration[5.0]
|
|||
|
||||
create_table :reports do |t|
|
||||
t.integer :issue_id
|
||||
t.integer :reporter_user_id
|
||||
t.integer :user_id
|
||||
t.text :details, :null => false
|
||||
t.timestamps :null => false
|
||||
end
|
||||
|
||||
add_foreign_key :reports, :issues, :name => "reports_issue_id_fkey", :on_delete => :cascade
|
||||
add_foreign_key :reports, :users, :column => :reporter_user_id, :name => "reports_reporter_user_id_fkey", :on_delete => :cascade
|
||||
add_foreign_key :reports, :users, :column => :user_id, :name => "reports_user_id_fkey", :on_delete => :cascade
|
||||
|
||||
add_index :reports, :reporter_user_id
|
||||
add_index :reports, :user_id
|
||||
add_index :reports, :issue_id
|
||||
|
||||
create_table :issue_comments do |t|
|
||||
t.integer :issue_id, :null => false
|
||||
t.integer :commenter_user_id, :null => false
|
||||
t.integer :user_id, :null => false
|
||||
t.text :body, :null => false
|
||||
t.timestamps :null => false
|
||||
end
|
||||
|
||||
add_foreign_key :issue_comments, :issues, :name => "issue_comments_issue_id_fkey", :on_delete => :cascade
|
||||
add_foreign_key :issue_comments, :users, :column => :commenter_user_id, :name => "issue_comments_commenter_user_id", :on_delete => :cascade
|
||||
add_foreign_key :issue_comments, :users, :column => :user_id, :name => "issue_comments_user_id", :on_delete => :cascade
|
||||
|
||||
add_index :issue_comments, :commenter_user_id
|
||||
add_index :issue_comments, :user_id
|
||||
add_index :issue_comments, :issue_id
|
||||
end
|
||||
end
|
||||
|
|
|
@ -692,7 +692,7 @@ ALTER SEQUENCE gpx_files_id_seq OWNED BY gpx_files.id;
|
|||
CREATE TABLE issue_comments (
|
||||
id integer NOT NULL,
|
||||
issue_id integer NOT NULL,
|
||||
commenter_user_id integer NOT NULL,
|
||||
user_id integer NOT NULL,
|
||||
body text NOT NULL,
|
||||
created_at timestamp without time zone NOT NULL,
|
||||
updated_at timestamp without time zone NOT NULL
|
||||
|
@ -1065,7 +1065,7 @@ CREATE TABLE relations (
|
|||
CREATE TABLE reports (
|
||||
id integer NOT NULL,
|
||||
issue_id integer,
|
||||
reporter_user_id integer,
|
||||
user_id integer,
|
||||
details text NOT NULL,
|
||||
created_at timestamp without time zone NOT NULL,
|
||||
updated_at timestamp without time zone NOT NULL
|
||||
|
@ -2030,13 +2030,6 @@ CREATE INDEX index_client_applications_on_user_id ON client_applications USING b
|
|||
CREATE INDEX index_diary_entry_subscriptions_on_diary_entry_id ON diary_entry_subscriptions USING btree (diary_entry_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_issue_comments_on_commenter_user_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_issue_comments_on_commenter_user_id ON issue_comments USING btree (commenter_user_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_issue_comments_on_issue_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -2044,6 +2037,13 @@ CREATE INDEX index_issue_comments_on_commenter_user_id ON issue_comments USING b
|
|||
CREATE INDEX index_issue_comments_on_issue_id ON issue_comments USING btree (issue_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_issue_comments_on_user_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_issue_comments_on_user_id ON issue_comments USING btree (user_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_issues_on_reportable_id_and_reportable_type; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -2108,10 +2108,10 @@ CREATE INDEX index_reports_on_issue_id ON reports USING btree (issue_id);
|
|||
|
||||
|
||||
--
|
||||
-- Name: index_reports_on_reporter_user_id; Type: INDEX; Schema: public; Owner: -
|
||||
-- Name: index_reports_on_user_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_reports_on_reporter_user_id ON reports USING btree (reporter_user_id);
|
||||
CREATE INDEX index_reports_on_user_id ON reports USING btree (user_id);
|
||||
|
||||
|
||||
--
|
||||
|
@ -2526,14 +2526,6 @@ ALTER TABLE ONLY gpx_files
|
|||
ADD CONSTRAINT gpx_files_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: issue_comments_commenter_user_id; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY issue_comments
|
||||
ADD CONSTRAINT issue_comments_commenter_user_id FOREIGN KEY (commenter_user_id) REFERENCES users(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: issue_comments_issue_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -2542,6 +2534,14 @@ ALTER TABLE ONLY issue_comments
|
|||
ADD CONSTRAINT issue_comments_issue_id_fkey FOREIGN KEY (issue_id) REFERENCES issues(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: issue_comments_user_id; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY issue_comments
|
||||
ADD CONSTRAINT issue_comments_user_id FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: issues_reported_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -2679,11 +2679,11 @@ ALTER TABLE ONLY reports
|
|||
|
||||
|
||||
--
|
||||
-- Name: reports_reporter_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
-- Name: reports_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY reports
|
||||
ADD CONSTRAINT reports_reporter_user_id_fkey FOREIGN KEY (reporter_user_id) REFERENCES users(id) ON DELETE CASCADE;
|
||||
ADD CONSTRAINT reports_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue