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

C# random value from dictionary and tuple -

cgi - How do I interpret URLs without extension as files rather than missing directories in nginx? -

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