ruby on rails - Problem with activerecord find -
i have 5 tables , related between. everythings good, perfectly! tried make script, if in inquiry table field is_answered = 0, find respondents (by respondent_id in question table) , send them letter have mistake!
i have code:
inquiry = inquiry.find(:all, :conditions => ["is_answered = 0"]) question = inquiry.question respondents = respondent.find(:all, :conditions => ["id = (?)", question.user_id]) respondents.each |r| notifier.deliver_user_notification(inquiry) end and when typing ruby blah.rb error:
undefined method `question' #<array:0x7f646c82b568> what mistake?
ps - inquiry table (id, question_id, respondent_id) relationship table between questions , answers. pss - respondent table related inquiry.
the problem have more inquiry following returns array.
inquiry.find(:all, :conditions => ["is_answered = 0"]) try following, mindful of how many sql queries does, there optimisations can made:
inquiry = inquiry.find(:all, :conditions => ["is_answered = 0"]) inquiry.each |i| question = i.question respondents = respondent.find(:all, :conditions => ["id = (?)", question.user_id]) respondents.each |r| notifier.deliver_user_notification(inquiry) end end
Comments
Post a Comment