Ruby on rails 4 rails的作用域有很多关联

Ruby on rails 4 rails的作用域有很多关联,ruby-on-rails-4,scope,associations,has-many,Ruby On Rails 4,Scope,Associations,Has Many,我有两种表演模式(戏剧或喜剧中的表演)。它们在模型中的关联方式如下: class Show < ActiveRecord::Base has_many :performances, :dependent => :destroy accepts_nested_attributes_for :performances end class Performance < ActiveRecord::Base belongs_to :show end class Show:

我有两种表演模式(戏剧或喜剧中的表演)。它们在模型中的关联方式如下:

class Show < ActiveRecord::Base
  has_many :performances, :dependent => :destroy
  accepts_nested_attributes_for :performances
end

class Performance < ActiveRecord::Base
  belongs_to :show
end
class Show:破坏
为:性能接受\u嵌套的\u属性\u
结束
类性能
在性能模型中,有一个日期时间称为:开始时间

我如何在模型中定义一个范围,该范围返回所有演出,其中至少有一场演出:开始时间在未来

class Show < ActiveRecord::Base
   has_many :performances, :dependent => :destroy
   accepts_nested_attributes_for :performances

   scope :shows_with_pending_performance, includes(:performances).where("performances.start_time >= ? ", Date.today)
end

class Performance < ActiveRecord::Base
   belongs_to :show
end
另外,我如何定义一个范围来返回所有没有任何性能的节目,其:开始时间在未来?

class Showclass Show < ActiveRecord::Base
   has_many :performances, :dependent => :destroy
   accepts_nested_attributes_for :performances

   scope :shows_with_pending_performance, includes(:performances).where("performances.start_time >= ? ", Date.today)
end

class Performance < ActiveRecord::Base
   belongs_to :show
end
有许多:性能,:依赖=>:破坏 为:性能接受\u嵌套的\u属性\u 范围:显示具有待定性能的性能,包括(:性能)。其中(“performances.start\u time>=?”,Date.today) 结束 类性能你的问题是什么?我想已经很清楚了。我将把它改为问题。有两个。好的…@KevinM如果我的建议是正确的,请确认它是解决方案