I have two tables: Stores and products. The store model has a has_many :products and the products has a belongs_to :store
has_many :products
belongs_to :store
I\'m trying to do
You have it backwards. Since you can have many stores, Rails will not return all the products where open: true.
open: true
You need to join and lookup the products where the store is open.
Product.joins(:store).where(store: {open: true}).where("created_at <= ?", 1.month.ago)