ruby on rails - :class => "Insert Random Class Name Here" -
what point of doing this?
class user has_many :students, :class_name => "coachstudent", foreign_key: "coach_user_id" end class coachstudent belongs_to :student, :class_name => "user", :foreign_key => "student_user_id" end
why?
why not user has many students, , student belongs user? that's traditional way, yes?
edit
my befuddlement stems fact there no student class per se. it's listed in code above. hence question.
ps. feel free rename post @ loss on how title it.
:class_name gives flexibility name associations whatever want , make code more readable , reusable. :foreign_key attribute again allows decide field want foreign key.
if go usual convention:
class user has_many :students end class coachstudent belongs_to :student end
activerecord default, use _id foreign key , try find class student
associations. in case, want use :students
association name , map coachstudent
. flexibility :class_name convention.
Comments
Post a Comment