ruby on rails 4 - How to filter query result? -
how filter out experiments hasn't associated circuit?
my experiment model:
has_many :circuits
my query:
@experiments = experiment.where(:public=>true).where( 'updated_at >= :one_month_ago, :one_month_ago => time.now - 30.days )
so, need avoid experiment circuits associated equal zero. idea?
i need avoid experiment circuits associated equal zero
one way setting validation
on foreign_key(experiment_id)
if have it.
class circuit < activerecord::base belongs_to :experiment validates :experiment_id, :presence=>true end
so,by setting above validation,you can make sure every circuit associated expeiment
.
Comments
Post a Comment