[Ilugc] mysql optimization

  • From: shakthimaan@xxxxxxxxx (Shakthi Kannan)
  • Date: Fri Jul 16 10:16:52 2010

Hi,

--- On Fri, Jul 16, 2010 at 8:43 AM, Deepan Chakravarthy
<codeshepherd@xxxxxxxxx> wrote:
| You are correct. If user P belongs to group A,B, then P can answer
| questions in both group A and B. (remember there is only one question
| per group)
\--

Can you try the has_many :through association [1]?

class User < ActiveRecord::Base
  has_many :answers
  has_many :groups, :through => answers
end

class Answer < ActiveRecord::Base
   belongs_to :user
   belongs_to :group
end

class Group < ActiveRecord::Base
   has_many :answers
   has_many :users, :through => answers
end

Example table schema:

  Users:     id, name
  Answers: id, user_id, group_id, answer
  Groups:   id, question

SK

[1] has_many :through association.
http://guides.rubyonrails.org/association_basics.html#the-has-many-through-association

-- 
Shakthi Kannan
http://www.shakthimaan.com

Other related posts: