I'm assuming client == company. Here an example for 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
Here an example for 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
For the import you should do it in a special order:
Client
, Staff
, because they can exist independent of all other models
Project
, it depends only on Client
Job
, depends on Project
and Client
Stage
, depends on Staff
, Project
, Job
and Client