Skip to content

Instantly share code, notes, and snippets.

@kamipo
Last active July 7, 2019 09:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamipo/e9d609c1f57de784c79a7f854d44be57 to your computer and use it in GitHub Desktop.
Save kamipo/e9d609c1f57de784c79a7f854d44be57 to your computer and use it in GitHub Desktop.
diff --git a/activerecord/test/cases/associations/inner_join_association_test.rb b/activerecord/test/cases/associations/inner_join_association_test.rb
index e0dac01f4a..ebba6b28b7 100644
--- a/activerecord/test/cases/associations/inner_join_association_test.rb
+++ b/activerecord/test/cases/associations/inner_join_association_test.rb
@@ -13,7 +13,18 @@
class InnerJoinAssociationTest < ActiveRecord::TestCase
fixtures :authors, :author_addresses, :essays, :posts, :comments, :categories, :categories_posts, :categorizations,
- :taggings, :tags
+ :taggings, :tags, :people
+
+ def test_includes
+ person = Person.includes(agents: { agents: :agents }).last
+
+ assert person
+ assert_no_queries do
+ assert person.agents.last
+ assert person.agents.last.agents.last
+ assert person.agents.last.agents.last.primary_contact.agents.last.agents.last
+ end
+ end
def test_construct_finder_sql_applies_aliases_tables_on_association_conditions
result = Author.joins(:thinking_posts, :welcome_posts).to_a
diff --git a/activerecord/test/models/person.rb b/activerecord/test/models/person.rb
index 0dfd29e45e..99e8cdc464 100644
--- a/activerecord/test/models/person.rb
+++ b/activerecord/test/models/person.rb
@@ -28,7 +28,7 @@ class Person < ActiveRecord::Base
has_many :jobs_with_dependent_nullify, source: :job, through: :references, dependent: :nullify
belongs_to :primary_contact, class_name: "Person"
- has_many :agents, class_name: "Person", foreign_key: "primary_contact_id"
+ has_many :agents, class_name: "Person", foreign_key: "primary_contact_id", inverse_of: :primary_contact
has_many :agents_of_agents, through: :agents, source: :agents
belongs_to :number1_fan, class_name: "Person"
@kamipo
Copy link
Author

kamipo commented Jul 6, 2019

% ARCONN=sqlite3 bundle exec ruby -w -Itest test/cases/associations/inner_join_association_test.rb -n test_includes
Using sqlite3
Run options: -n test_includes --seed 17582

# Running:

.

Finished in 0.078855s, 12.6815 runs/s, 50.7260 assertions/s.
1 runs, 4 assertions, 0 failures, 0 errors, 0 skips

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment