Skip to content

Instantly share code, notes, and snippets.

@Frank004

Frank004/client_company.rb Secret

Last active Mar 24, 2016
Embed
What would you like to do?
class ClientCompany < ActiveRecord::Base
belongs_to :company
belongs_to :service_company
has_many :client_users, :dependent => :destroy
has_many :users, :through => :client_users
end
# == Schema Information
#
# Table name: client_users
#
# id :integer not null, primary key
# client_company_id :integer
# user_id :integer
# created_at :datetime
# updated_at :datetime
#
class ClientUser < ActiveRecord::Base
belongs_to :user, :dependent => :destroy
belongs_to :client_company
has_one :company, :through => :client_company
end
# == Schema Information
#
# Table name: client_users
#
# id :integer not null, primary key
# client_company_id :integer
# user_id :integer
# created_at :datetime
# updated_at :datetime
#
class Company < ActiveRecord::Base
has_one :service_company, :dependent => :destroy
has_one :client_company, :dependent => :destroy
has_many :client_users, :through => :client_company
has_many :users, :through => :client_users
has_many :service_users, :through => :service_company
has_many :users, :through => :service_users
end
# == Schema Information
#
# Table name: companies
#
# id :integer not null, primary key
# name :string(255)
# address :string(255)
# city :string(255)
# state :string(255)
# country :string(255)
# phone :string(255)
# created_at :datetime
# updated_at :datetime
# photo_file_name :string(255)
# photo_content_type :string(255)
# photo_file_size :integer
# photo_updated_at :datetime
#
def show
if current_user.service_user
@project = current_user.service_user.projects.find(params[:id])
else
@project = current_user.client_user.projects.find(params[:id])
end
end
class ServiceCompany < ActiveRecord::Base
belongs_to :company
has_many :service_users, :dependent => :destroy
has_many :client_users, :through => :client_companies, :dependent => :destroy
has_many :users, :through => :service_users
has_many :client_companies, :dependent => :destroy
end
# == Schema Information
#
# Table name: service_companies
#
# id :integer not null, primary key
# company_id :integer
# week_start_day :integer
# created_at :datetime
# updated_at :datetime
#
class ServiceUser < ActiveRecord::Base
belongs_to :user, :dependent => :destroy
belongs_to :service_company
has_one :company, :through => :service_company
end
# == Schema Information
#
# Table name: service_users
#
# id :integer not null, primary key
# service_company_id :integer
# user_id :integer
# created_at :datetime
# updated_at :datetime
#
class User < ActiveRecord::Base
has_one :client_user
has_one :client_company, :through => :client_user
has_one :service_user
has_one :service_company, :through => :service_user
belongs_to :company
end
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# email :string(255) default(""), not null
# username :string(255) default(""), not null
# encrypted_password :string(255) default(""), not null
# reset_password_token :string(255)
# reset_password_sent_at :datetime
# remember_created_at :datetime
# sign_in_count :integer default(0), not null
# current_sign_in_at :datetime
# last_sign_in_at :datetime
# current_sign_in_ip :string(255)
# last_sign_in_ip :string(255)
# role :string(255) not null
# created_at :datetime
# updated_at :datetime
# first_name :string(255)
# last_name :string(255)
# attachment_file_name :string(255)
# attachment_content_type :string(255)
# attachment_file_size :integer
# attachment_updated_at :datetime
# last_active_at :datetime
# banned :boolean default(FALSE)
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.