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

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -