Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 轨道模拟约束和子约束_Ruby On Rails 4_Mongoid_Constraints_Multiple Inheritance_Matching - Fatal编程技术网

Ruby on rails 4 轨道模拟约束和子约束

Ruby on rails 4 轨道模拟约束和子约束,ruby-on-rails-4,mongoid,constraints,multiple-inheritance,matching,Ruby On Rails 4,Mongoid,Constraints,Multiple Inheritance,Matching,我正在构建一个调度平台,其中包含当前项目的任务 假设项目有一些全局约束(资金、人员等),每个任务也有各自的约束 重要的是,我必须将每个全局约束与同一项目任务的每个约束相匹配 现在真正重要的是,除了有一个性质(财务->浮动,人员->整数)外,约束还可以有一个类型(例如:工资成本、原材料成本等) rails的方法是什么 我想到了类似的东西,但看起来(?)有点重复: class Constraint field :type, type: String belongs_to :task

我正在构建一个调度平台,其中包含当前项目的任务

假设项目有一些全局约束(资金、人员等),每个任务也有各自的约束

重要的是,我必须将每个全局约束与同一项目任务的每个约束相匹配

现在真正重要的是,除了有一个性质(财务->浮动,人员->整数)外,约束还可以有一个类型(例如:工资成本、原材料成本等)

rails的方法是什么

我想到了类似的东西,但看起来(?)有点重复:

class Constraint
    field :type, type: String
    belongs_to :task
    belongs_to :global_constraint
end

class Constraint::Financial < Constraint
    field :cost, type: Float
end

class Constraint::People < Constraint
    field :number, type: Integer
end
...
示例:

GlobalConstraint::Financial
def check_integrity
    sum = Float.new
    self.sonstraints.each do |constraint|
        sum += constraint.cost
    end
    sum < cost
end

GlobalConstraint::People
def check_integrity
    sum = Integer.new
    self.sonstraints.each do |constraint|
        sum += constraint.cost
    end
    sum < number
end
GlobalConstraint::财务
def检查\u完整性
sum=Float.new
self.sonstraint.each do|约束|
总和+=约束成本
结束
总和<成本
结束
全球约束::人
def检查\u完整性
sum=Integer.new
self.sonstraint.each do|约束|
总和+=约束成本
结束
总和<数字
结束
(inside the Constraint class)

def find_global_constraint
        self.global_constraint = self.task.project.global_constraints.find_by(:type => self.type)
end

(inside GlobalConstraint::xxx class) :

def check_integrity
    "Requires custom implementation !"
end
GlobalConstraint::Financial
def check_integrity
    sum = Float.new
    self.sonstraints.each do |constraint|
        sum += constraint.cost
    end
    sum < cost
end

GlobalConstraint::People
def check_integrity
    sum = Integer.new
    self.sonstraints.each do |constraint|
        sum += constraint.cost
    end
    sum < number
end