Ruby on rails Rails设置了在简单表单关联中使用的范围

Ruby on rails Rails设置了在简单表单关联中使用的范围,ruby-on-rails,Ruby On Rails,我有一个表单,我想将新发票与具有外部类型(类型中的布尔字段称为内部)的工单关联(工单属于类型) 这是我想使用的代码: <%= f.association :workorder, :collection => Workorder.external, :label_method => :wonum_desc, :label => 'Work Order' %> 谢谢你的帮助 必须包括类型模型,然后在类型表的内部字段中添加条件: scope :external, inc

我有一个表单,我想将新发票与具有外部类型(类型中的布尔字段称为内部)的工单关联(工单属于类型)

这是我想使用的代码:

<%= f.association :workorder, :collection => Workorder.external, :label_method => :wonum_desc, :label => 'Work Order' %>

谢谢你的帮助

必须包括类型模型,然后在类型表的内部字段中添加条件:

scope :external, includes(:type).where(types: { internal: false })
# notice the syntax:       ^^^^        ^^^^^
# in includes/joins, use the relation's name (here, Workoder belongs_to :type)
# in where, use the table's name (usually the pluralized version of the relation)

谢谢你的回答!
scope :external, includes(:type).where(types: { internal: false })
# notice the syntax:       ^^^^        ^^^^^
# in includes/joins, use the relation's name (here, Workoder belongs_to :type)
# in where, use the table's name (usually the pluralized version of the relation)