1
當我這樣做時,有什麼辦法可以防止查詢db的問題。如何插入使用mongoid,而不必做額外的查詢?
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