Я предполагаю, что клиент == компания.Вот пример для ActiveRecord
class Stage < ActiveRecord::Base
belongs_to :staff
belongs_to :project
belongs_to :job
belongs_to :company, :class => "Client"
end
class Project < ActiveRecord::Base
belongs_to :company, :class => "Client"
has_many :stages
end
class Job < ActiveRecord::Base
belongs_to :project
belongs_to :company, :class => "Client"
has_many :stages
end
class Client < ActiveRecord::Base
has_many :jobs, :foreign_key => "company_id"
has_many :projects, :foreign_key => "company_id"
has_many :stages, :foreign_key => "company_id"
end
class Staff < ActiveRecord::Base
has_many :stages
end
Вот пример для DataMapper:
class Stage
include DataMapper::Resource
property :id, Serial
belongs_to :staff
belongs_to :project
belongs_to :job
belongs_to :company, "Client"
end
class Project
include DataMapper::Resource
property :id, Serial
belongs_to :company, "Client"
has n, :stages
end
class Job
include DataMapper::Resource
property :id, Serial
belongs_to :project
belongs_to :company, "Client"
has n, :stages
end
class Client
include DataMapper::Resource
property :id, Serial
has n, :jobs, :foreign_key => "company_id"
has n, :projects, :foreign_key => "company_id"
has n, :stages, :foreign_key => "company_id"
end
class Staff
include DataMapper::Resource
property :id, Serial
has n, :stages
end
Для импорта вы должны сделать это в специальном порядке:
Client
, Staff
, поскольку они могут существовать независимо от всех других моделей Project
, это зависит только от Client
Job
, зависит от Project
иClient
Stage
, зависит от Staff
, Project
, Job
и Client