Unexpected behaviour in rails when defining class_name in habtm -


I have two models (courses and dancers). There may be many dancers (students) and teachers (also dancers) in a course. Teachers can be students of other courses.

I define tables as follows:

  create_table "course_enrollments" ,: force = & gt; Is true T | t.integer "dancer_id" ,: null = & gt; Wrong t.integer "course_id" ,: null = & gt; Incorrect t.datetime "attended_on" ,: null => Wrong end create_table "course",: force => Is true T | T.string "name" ,: null = & gt; Wrong t.string "genre" t.datetime "created_at" ,: null = & gt; Incorrect t.datetime "updated_at" ,: null = & gt; False end create_table "courses_teachers" ,: id = & gt; Wrong, force = & gt; Is true T | t.integer "course_id" ,: null = & gt; False T.E.E.E.E.G. "Teacher_ID" ,: Cord = & gt; False end create_table "dancers" ,: force => Is true T | T.string "first_name" ,: null = & gt; Wrong t.string "last_name" ,: null = & gt; Wrong t.datetime "created_at" ,: null = & gt; Incorrect t.datetime "updated_at" ,: null = & gt; False end   

and classes:

  class dancer & lt; ActiveRecord :: Base is: Medium: Course_Administrations are: Medium: Course, By: = & gt; : course_enrollments are many: teachers ,: through => : Course End Class Course & lt; ActiveRecord :: Base is: Medium: Course_Advanced_Maya: Dancers ,: By: = & gt; : Course_enrollments is_and_bangs_to_man: teacher, class_name = & gt; End of 'Dancer' class course order & lt; ActiveRecord :: Base is_to: Dancer related_to: Course ending   

Based on the guide (), I hope that the teachers will be able to find table course_takers for the course specialty and the foreign key. Use the teacher_id in the form. Instead, it is looking for courses_dancers and dancer_id, perhaps setting class_name to 'dancer' is it a design or is it a bug? If I work instead, then I can work it out:

  is_and_ballong _____ many: teachers, class_name = & gt; 'Dancer' ,: join_table = & gt;  

"post-text" itemprop = "text">

If you see it, then there is an option for foreign_key and association_foreign_key . Try the following

  is_and_belge_to_man: teacher ,: class_name = & gt; 'Dancer' ,: join_table = & gt; : Course_Tekers ,: foreign_key = & gt; : course_id ,: association_foreign_key = & gt; : Teacher_ID   

I'm not sure that it will work without having to go without the foreign_key option, but maybe it will try without first.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -