Set up all models and relationships between them
This commit is contained in:
parent
3232d2fb94
commit
294758c7b2
|
@ -0,0 +1,6 @@
|
||||||
|
class Employer < ApplicationRecord
|
||||||
|
has_many :participants
|
||||||
|
has_many :workers, through: :participants
|
||||||
|
# Association with Vendor if needed
|
||||||
|
end
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class Participant < ApplicationRecord
|
||||||
|
belongs_to :employer
|
||||||
|
has_and_belongs_to_many :programs
|
||||||
|
has_many :workers
|
||||||
|
end
|
|
@ -0,0 +1,4 @@
|
||||||
|
class Program < ApplicationRecord
|
||||||
|
has_and_belongs_to_many :participants
|
||||||
|
end
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class Vendor < ApplicationRecord
|
||||||
|
# Many-to-many relationships
|
||||||
|
has_and_belongs_to_many :participants
|
||||||
|
has_and_belongs_to_many :employers
|
||||||
|
end
|
|
@ -0,0 +1,7 @@
|
||||||
|
class Worker < ApplicationRecord
|
||||||
|
# One-to-many relationship with Participants
|
||||||
|
has_many :participants
|
||||||
|
|
||||||
|
# Many-to-many relationship with Employers through Participants
|
||||||
|
has_many :employers, through: :participants
|
||||||
|
end
|
|
@ -0,0 +1,17 @@
|
||||||
|
class CreateParticipants < ActiveRecord::Migration[7.1]
|
||||||
|
def change
|
||||||
|
create_table :participants do |t|
|
||||||
|
t.string :name
|
||||||
|
t.string :address
|
||||||
|
t.string :phone
|
||||||
|
t.string :email
|
||||||
|
t.string :mci
|
||||||
|
t.date :dob
|
||||||
|
t.string :ssn
|
||||||
|
t.string :gender
|
||||||
|
t.references :employer, null: false, foreign_key: true
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,16 @@
|
||||||
|
class CreateEmployers < ActiveRecord::Migration[7.1]
|
||||||
|
def change
|
||||||
|
create_table :employers do |t|
|
||||||
|
t.string :name
|
||||||
|
t.string :address
|
||||||
|
t.string :phone
|
||||||
|
t.string :email
|
||||||
|
t.string :tin
|
||||||
|
t.date :dob
|
||||||
|
t.string :ssn
|
||||||
|
t.string :gender
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,15 @@
|
||||||
|
class CreateWorkers < ActiveRecord::Migration[7.1]
|
||||||
|
def change
|
||||||
|
create_table :workers do |t|
|
||||||
|
t.string :name
|
||||||
|
t.string :address
|
||||||
|
t.string :phone
|
||||||
|
t.string :email
|
||||||
|
t.date :dob
|
||||||
|
t.string :ssn
|
||||||
|
t.string :gender
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,15 @@
|
||||||
|
class CreateVendors < ActiveRecord::Migration[7.1]
|
||||||
|
def change
|
||||||
|
create_table :vendors do |t|
|
||||||
|
t.string :name
|
||||||
|
t.string :address
|
||||||
|
t.string :phone
|
||||||
|
t.string :email
|
||||||
|
t.string :dba
|
||||||
|
t.string :tin
|
||||||
|
t.string :contact_name
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,9 @@
|
||||||
|
class CreatePrograms < ActiveRecord::Migration[7.1]
|
||||||
|
def change
|
||||||
|
create_table :programs do |t|
|
||||||
|
t.string :name
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,8 @@
|
||||||
|
class CreateJoinTableParticipantProgram < ActiveRecord::Migration[7.1]
|
||||||
|
def change
|
||||||
|
create_join_table :participants, :programs do |t|
|
||||||
|
# t.index [:participant_id, :program_id]
|
||||||
|
# t.index [:program_id, :participant_id]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddWorkerToParticipants < ActiveRecord::Migration[7.1]
|
||||||
|
def change
|
||||||
|
add_reference :participants, :worker, null: false, foreign_key: true
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,8 @@
|
||||||
|
class CreateJoinTableVendorParticipant < ActiveRecord::Migration[7.1]
|
||||||
|
def change
|
||||||
|
create_join_table :vendors, :participants do |t|
|
||||||
|
# t.index [:vendor_id, :participant_id]
|
||||||
|
# t.index [:participant_id, :vendor_id]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,8 @@
|
||||||
|
class CreateJoinTableVendorEmployer < ActiveRecord::Migration[7.1]
|
||||||
|
def change
|
||||||
|
create_join_table :vendors, :employers do |t|
|
||||||
|
# t.index [:vendor_id, :employer_id]
|
||||||
|
# t.index [:employer_id, :vendor_id]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,58 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.1].define(version: 2024_01_15_041321) do
|
ActiveRecord::Schema[7.1].define(version: 2024_01_17_025159) do
|
||||||
|
create_table "employers", force: :cascade do |t|
|
||||||
|
t.string "name"
|
||||||
|
t.string "address"
|
||||||
|
t.string "phone"
|
||||||
|
t.string "email"
|
||||||
|
t.string "tin"
|
||||||
|
t.date "dob"
|
||||||
|
t.string "ssn"
|
||||||
|
t.string "gender"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "employers_vendors", id: false, force: :cascade do |t|
|
||||||
|
t.integer "vendor_id", null: false
|
||||||
|
t.integer "employer_id", null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "participants", force: :cascade do |t|
|
||||||
|
t.string "name"
|
||||||
|
t.string "address"
|
||||||
|
t.string "phone"
|
||||||
|
t.string "email"
|
||||||
|
t.string "mci"
|
||||||
|
t.date "dob"
|
||||||
|
t.string "ssn"
|
||||||
|
t.string "gender"
|
||||||
|
t.integer "employer_id", null: false
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.integer "worker_id", null: false
|
||||||
|
t.index ["employer_id"], name: "index_participants_on_employer_id"
|
||||||
|
t.index ["worker_id"], name: "index_participants_on_worker_id"
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "participants_programs", id: false, force: :cascade do |t|
|
||||||
|
t.integer "participant_id", null: false
|
||||||
|
t.integer "program_id", null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "participants_vendors", id: false, force: :cascade do |t|
|
||||||
|
t.integer "vendor_id", null: false
|
||||||
|
t.integer "participant_id", null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "programs", force: :cascade do |t|
|
||||||
|
t.string "name"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
create_table "users", force: :cascade do |t|
|
create_table "users", force: :cascade do |t|
|
||||||
t.string "email", default: "", null: false
|
t.string "email", default: "", null: false
|
||||||
t.string "encrypted_password", default: "", null: false
|
t.string "encrypted_password", default: "", null: false
|
||||||
|
@ -23,4 +74,30 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_15_041321) do
|
||||||
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "vendors", force: :cascade do |t|
|
||||||
|
t.string "name"
|
||||||
|
t.string "address"
|
||||||
|
t.string "phone"
|
||||||
|
t.string "email"
|
||||||
|
t.string "dba"
|
||||||
|
t.string "tin"
|
||||||
|
t.string "contact_name"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "workers", force: :cascade do |t|
|
||||||
|
t.string "name"
|
||||||
|
t.string "address"
|
||||||
|
t.string "phone"
|
||||||
|
t.string "email"
|
||||||
|
t.date "dob"
|
||||||
|
t.string "ssn"
|
||||||
|
t.string "gender"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
add_foreign_key "participants", "employers"
|
||||||
|
add_foreign_key "participants", "workers"
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
name: MyString
|
||||||
|
address: MyString
|
||||||
|
phone: MyString
|
||||||
|
email: MyString
|
||||||
|
tin: MyString
|
||||||
|
dob: 2024-01-16
|
||||||
|
ssn: MyString
|
||||||
|
gender: MyString
|
||||||
|
|
||||||
|
two:
|
||||||
|
name: MyString
|
||||||
|
address: MyString
|
||||||
|
phone: MyString
|
||||||
|
email: MyString
|
||||||
|
tin: MyString
|
||||||
|
dob: 2024-01-16
|
||||||
|
ssn: MyString
|
||||||
|
gender: MyString
|
|
@ -0,0 +1,23 @@
|
||||||
|
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
name: MyString
|
||||||
|
address: MyString
|
||||||
|
phone: MyString
|
||||||
|
email: MyString
|
||||||
|
mci: MyString
|
||||||
|
dob: 2024-01-16
|
||||||
|
ssn: MyString
|
||||||
|
gender: MyString
|
||||||
|
employer: one
|
||||||
|
|
||||||
|
two:
|
||||||
|
name: MyString
|
||||||
|
address: MyString
|
||||||
|
phone: MyString
|
||||||
|
email: MyString
|
||||||
|
mci: MyString
|
||||||
|
dob: 2024-01-16
|
||||||
|
ssn: MyString
|
||||||
|
gender: MyString
|
||||||
|
employer: two
|
|
@ -0,0 +1,7 @@
|
||||||
|
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
name: MyString
|
||||||
|
|
||||||
|
two:
|
||||||
|
name: MyString
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
name: MyString
|
||||||
|
address: MyString
|
||||||
|
phone: MyString
|
||||||
|
email: MyString
|
||||||
|
dba: MyString
|
||||||
|
tin: MyString
|
||||||
|
contact_name: MyString
|
||||||
|
|
||||||
|
two:
|
||||||
|
name: MyString
|
||||||
|
address: MyString
|
||||||
|
phone: MyString
|
||||||
|
email: MyString
|
||||||
|
dba: MyString
|
||||||
|
tin: MyString
|
||||||
|
contact_name: MyString
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
name: MyString
|
||||||
|
address: MyString
|
||||||
|
phone: MyString
|
||||||
|
email: MyString
|
||||||
|
dob: 2024-01-16
|
||||||
|
ssn: MyString
|
||||||
|
gender: MyString
|
||||||
|
|
||||||
|
two:
|
||||||
|
name: MyString
|
||||||
|
address: MyString
|
||||||
|
phone: MyString
|
||||||
|
email: MyString
|
||||||
|
dob: 2024-01-16
|
||||||
|
ssn: MyString
|
||||||
|
gender: MyString
|
|
@ -0,0 +1,7 @@
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class EmployerTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
|
@ -0,0 +1,7 @@
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class ParticipantTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
|
@ -0,0 +1,7 @@
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class ProgramTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
|
@ -0,0 +1,7 @@
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class VendorTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
|
@ -0,0 +1,7 @@
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class WorkerTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
Loading…
Reference in New Issue