Skip to content
This repository was archived by the owner on Nov 19, 2025. It is now read-only.

Commit ce0a859

Browse files
committed
Test joins within a database (works) and across databases (fail)
You can't join across databases.
1 parent 870b6ec commit ce0a859

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

test/connection_switching_test.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,16 +617,27 @@ class ShardedModel < ActiveRecord::Base
617617
end
618618

619619
it "supports implicit joins" do
620-
accounts = Account.includes(:tickets)
621-
accounts = accounts.references(:tickets) if ActiveRecord::VERSION::MAJOR >= 4
622-
assert_equal ["slave_name", "slave_name2"], accounts.order('tickets.id').map(&:name).sort
620+
accounts = Account.includes(:account_things)
621+
accounts = accounts.references(:account_things) if ActiveRecord::VERSION::MAJOR >= 4
622+
assert_equal ["slave_name", "slave_name2"], accounts.order('account_things.id').map(&:name).sort
623623
end
624624

625625
it "supports joins" do
626-
accounts = Account.joins('LEFT OUTER JOIN tickets ON tickets.account_id = accounts.id').map(&:name).sort
626+
accounts = Account.joins('LEFT OUTER JOIN account_things ON account_things.account_id = accounts.id').map(&:name).sort
627627
assert_equal ["slave_name", "slave_name2"], accounts
628628
end
629629

630+
it "does not support implicit joins between an unsharded and a sharded table" do
631+
accounts = Account.includes(:tickets).order('tickets.id')
632+
accounts = accounts.references(:tickets) if ActiveRecord::VERSION::MAJOR >= 4
633+
assert_raises(ActiveRecord::StatementInvalid) { accounts.first }
634+
end
635+
636+
it "does not support explicit joins between an unsharded and a sharded table" do
637+
accounts = Account.joins('LEFT OUTER JOIN tickets ON tickets.account_id = accounts.id')
638+
assert_raises(ActiveRecord::StatementInvalid) { accounts.first }
639+
end
640+
630641
after do
631642
Account.on_slave_by_default = false
632643
Person.on_slave_by_default = false

0 commit comments

Comments
 (0)