有什么方法可以防止我在执行此操作时不必向数据库查询问题。
has_and_belongs_to_many :followed_questions, class_name: 'Question', inverse_of: nil
qid = "501928374"
q = Question.find(qid)
self.followed_questions << q unless self.followed_questions.include?(q)
self.save
我想做这个:
has_and_belongs_to_many :followed_questions, class_name: 'Question', inverse_of: nil
qid = "501928374"
self.followed_questions << qid unless self.followed_questions.include?(qid)
self.save