@@ -413,3 +413,63 @@ def test_find_by_with_uuid
413
413
assert_nil UuidPost . find_by ( id : 789 )
414
414
end
415
415
end
416
+
417
+ class PostgresqlUUIDHasManyThroughDisableJoinsTest < ActiveRecord ::PostgreSQLTestCase
418
+ include PostgresqlUUIDHelper
419
+
420
+ class UuidForum < ActiveRecord ::Base
421
+ self . table_name = "pg_uuid_forums"
422
+ has_many :uuid_posts , -> { order ( "title DESC" ) }
423
+ has_many :uuid_comments , through : :uuid_posts
424
+ has_many :uuid_comments_without_joins , through : :uuid_posts , source : :uuid_comments , disable_joins : true
425
+ end
426
+
427
+ class UuidPost < ActiveRecord ::Base
428
+ self . table_name = "pg_uuid_posts"
429
+ belongs_to :uuid_forum
430
+ has_many :uuid_comments
431
+ end
432
+
433
+ class UuidComment < ActiveRecord ::Base
434
+ self . table_name = "pg_uuid_comments"
435
+ belongs_to :uuid_post
436
+ has_one :uuid_forum , through : :uuid_post
437
+ has_one :uuid_forum_without_joins , through : :uuid_post , source : :uuid_forum , disable_joins : true
438
+ end
439
+
440
+ setup do
441
+ connection . transaction do
442
+ connection . create_table ( "pg_uuid_forums" , id : :uuid , **uuid_default ) do |t |
443
+ t . string "name"
444
+ end
445
+ connection . create_table ( "pg_uuid_posts" , id : :uuid , **uuid_default ) do |t |
446
+ t . references :uuid_forum , type : :uuid
447
+ t . string "title"
448
+ end
449
+ connection . create_table ( "pg_uuid_comments" , id : :uuid , **uuid_default ) do |t |
450
+ t . references :uuid_post , type : :uuid
451
+ t . string "content"
452
+ end
453
+ end
454
+ end
455
+
456
+ teardown do
457
+ drop_table "pg_uuid_comments"
458
+ drop_table "pg_uuid_posts"
459
+ drop_table "pg_uuid_forums"
460
+ end
461
+
462
+ def test_uuid_primary_key_and_disable_joins_with_delegate_cache
463
+ uuid_forum = UuidForum . create!
464
+ uuid_post_1 = uuid_forum . uuid_posts . create!
465
+ uuid_comment_1_1 = uuid_post_1 . uuid_comments . create!
466
+ uuid_comment_1_2 = uuid_post_1 . uuid_comments . create!
467
+ uuid_post_2 = uuid_forum . uuid_posts . create!
468
+ uuid_comment_2_1 = uuid_post_2 . uuid_comments . create!
469
+ uuid_comment_2_2 = uuid_post_2 . uuid_comments . create!
470
+ uuid_comment_2_3 = uuid_post_2 . uuid_comments . create!
471
+
472
+ assert_equal uuid_forum . uuid_comments_without_joins . order ( :id ) . to_a . map ( &:id ) . sort ,
473
+ [ uuid_comment_1_1 . id , uuid_comment_1_2 . id , uuid_comment_2_1 . id , uuid_comment_2_2 . id , uuid_comment_2_3 . id ] . sort
474
+ end
475
+ end
0 commit comments