Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable Joins UUID support #47476

Merged
merged 1 commit into from Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -30,7 +30,7 @@ def load
record[key]
end

records = ids.flat_map { |id| records_by_id[id.to_i] }
sj26 marked this conversation as resolved.
Show resolved Hide resolved
records = ids.flat_map { |id| records_by_id[id] }
records.compact!

@records = records
Expand Down
60 changes: 60 additions & 0 deletions activerecord/test/cases/adapters/postgresql/uuid_test.rb
Expand Up @@ -413,3 +413,63 @@ def test_find_by_with_uuid
assert_nil UuidPost.find_by(id: 789)
end
end

class PostgresqlUUIDHasManyThroughDisableJoinsTest < ActiveRecord::PostgreSQLTestCase
include PostgresqlUUIDHelper

class UuidForum < ActiveRecord::Base
self.table_name = "pg_uuid_forums"
has_many :uuid_posts, -> { order("title DESC") }
has_many :uuid_comments, through: :uuid_posts
has_many :uuid_comments_without_joins, through: :uuid_posts, source: :uuid_comments, disable_joins: true
end

class UuidPost < ActiveRecord::Base
self.table_name = "pg_uuid_posts"
belongs_to :uuid_forum
has_many :uuid_comments
end

class UuidComment < ActiveRecord::Base
self.table_name = "pg_uuid_comments"
belongs_to :uuid_post
has_one :uuid_forum, through: :uuid_post
has_one :uuid_forum_without_joins, through: :uuid_post, source: :uuid_forum, disable_joins: true
end

setup do
connection.transaction do
connection.create_table("pg_uuid_forums", id: :uuid, **uuid_default) do |t|
t.string "name"
end
connection.create_table("pg_uuid_posts", id: :uuid, **uuid_default) do |t|
t.references :uuid_forum, type: :uuid
t.string "title"
end
connection.create_table("pg_uuid_comments", id: :uuid, **uuid_default) do |t|
t.references :uuid_post, type: :uuid
t.string "content"
end
end
end

teardown do
drop_table "pg_uuid_comments"
drop_table "pg_uuid_posts"
drop_table "pg_uuid_forums"
end

def test_uuid_primary_key_and_disable_joins_with_delegate_cache
uuid_forum = UuidForum.create!
uuid_post_1 = uuid_forum.uuid_posts.create!
uuid_comment_1_1 = uuid_post_1.uuid_comments.create!
uuid_comment_1_2 = uuid_post_1.uuid_comments.create!
uuid_post_2 = uuid_forum.uuid_posts.create!
uuid_comment_2_1 = uuid_post_2.uuid_comments.create!
uuid_comment_2_2 = uuid_post_2.uuid_comments.create!
uuid_comment_2_3 = uuid_post_2.uuid_comments.create!

assert_equal uuid_forum.uuid_comments_without_joins.order(:id).to_a.map(&:id).sort,
[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
end
end