Skip to content

Commit 42d44c4

Browse files
committed
company refs for users, quotes
1 parent 521e86e commit 42d44c4

File tree

8 files changed

+30
-3
lines changed

8 files changed

+30
-3
lines changed

app/models/company.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
class Company < ApplicationRecord
2+
has_many :users, dependent: :destroy
3+
has_many :quotes, dependent: :destroy
4+
25
validates :name, presence: true
36
end

app/models/quote.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class Quote < ApplicationRecord
2+
belongs_to :company
3+
24
validates :name, presence: true
35

46
scope :desc_id_ordered, -> { order(id: :desc) }

app/models/user.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class User < ApplicationRecord
2-
# Include default devise modules. Others available are:
3-
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
42
devise :database_authenticatable, :validatable
3+
4+
belongs_to :company
55
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddCompanyReferenceToQuotes < ActiveRecord::Migration[7.1]
2+
def change
3+
add_reference :quotes, :company, null: false, foreign_key: true
4+
end
5+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddCompanyReferenceToUsers < ActiveRecord::Migration[7.1]
2+
def change
3+
add_reference :users, :company, null: false, foreign_key: true
4+
end
5+
end

db/schema.rb

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/quotes.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
one:
2+
company: kpmg
23
name: First quote
34

45
two:
6+
company: kpmg
57
name: Second quote
68

79
three:
10+
company: kpmg
811
name: Third quote

test/fixtures/users.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
accountant:
2+
company: kpmg
23
34
encrypted_password: <%= Devise::Encryptor.digest(User, 'password') %>
45

56
manager:
7+
company: kpmg
68
79
encrypted_password: <%= Devise::Encryptor.digest(User, 'password') %>
810

911
eavesdropper:
12+
company: pwc
1013
1114
encrypted_password: <%= Devise::Encryptor.digest(User, 'password') %>

0 commit comments

Comments
 (0)