ruby on rails - Twice belongs_to maps back to the same table 'User' -
class comment < activerecord::base belongs_to :commenter, :class_name => "user", :foreign_key => "commenter_user_id" belongs_to :student, :class_name => "user", :foreign_key => "student_user_id"
they both belong user.
i if done once because helps make more clearer or whatnot ...
but why twice map same table?!?!?
so, result comment columns this:
[0] "id", [1] "comment", [2] "student_user_id", [3] "commenter_user_id", [4] "created_at", [5] "updated_at", [6] "partnership_id"
please excuse if seems same previous question. me, it's not. or maybe didn't enough. hm.
a comment
can posted commentator
user
, comment
can posted student
user
best define way
class comment < activerecord::base belongs_to :commenter, :class_name => "user", :foreign_key => "commenter_user_id" belongs_to :student, :class_name => "user", :foreign_key => "student_user_id"
rather defining this
class comment < activerecord::base belongs_to :commenter belongs_to :student
Comments
Post a Comment