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)
结束
类性能