Rails scope through has_many association

I have two models for Show and Performance (to show, as in a play or a comedy show). In models, they are connected as follows:

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

The Performance model has the name datetime: start_time.

How to define a region in a model that returns all shows with at least one indicator whose: start_time in the future?

Also, how can I define an area that returns all impressions that do not have any characteristics whose: start_time in the future?

+7
scope ruby-on-rails-4 associations has-many
source share
1 answer
 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 
+7
source share

All Articles