나는 클라이언트 == 회사라고 가정하고 있습니다. 여기에 여기에
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
, 이는에만 의존합니다.
Job
는
Project
및
Stage
Client
에 따라 달라집니다 당신이 액티브 또는 DataMapper를 사용하고 Staff
, Project
, Job
및 Client
에 따라 달라집니다? (이들은 서로 다른 두 가지입니다) – mikej
죄송합니다, 나는 DataMapper를 사용하고 있지만 관계 유형이 유사하다고 가정합니까? 예 : 1 대 다수 등 – Tom