From 6a91a3307ff6556225ab8717617074cea20222e0 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 6 Sep 2013 17:14:07 -0700 Subject: hm:t join tables may not have a primary key --- .../associations/has_many_through_associations_test.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'activerecord/test/cases/associations/has_many_through_associations_test.rb') diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index 508faa9437..541f649ae9 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -64,6 +64,24 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase anonbook.subscribers.map(&:id).sort end + def test_no_pk_join_table_append + lesson = make_model 'Lesson' + student = make_model 'Student' + + lesson_student = make_model 'LessonStudent' + lesson_student.table_name = 'lessons_students' + + lesson_student.belongs_to :lesson, :class => lesson + lesson_student.belongs_to :student, :class => student + lesson.has_many :lesson_students, :class => lesson_student + lesson.has_many :students, :through => :lesson_students, :class => student + + sicp = lesson.new(:name => "SICP") + ben = student.new(:name => "Ben Bitdiddle") + sicp.students << ben + assert sicp.save! + end + def test_pk_is_not_required_for_join post = Post.includes(:scategories).first post2 = Post.includes(:categories).first -- cgit v1.2.3