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
[ci skip] correct for ActiveRecord::Associations::Preloader #20673
Conversation
@aditya-kapoor please use the PR body to explain the change. I'm not sure I understand why i'ts necessary. As far as I can tell the example only use the |
@senny I think there the If there was no Please correct if I am missing something. |
@aditya-kapoor why should it not work? # Activate the gem you are reporting the issue against.
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :authors do |t|
t.string :name
t.integer :age
end
create_table :books do |t|
t.string :title
t.integer :sales
t.belongs_to :author
end
end
class Author < ActiveRecord::Base
# columns: name, age
has_many :books
end
class Book < ActiveRecord::Base
# columns: title, sales
end
class ExampleTest < Minitest::Test
def test_example
Author.includes(:books).where(name: ['bell hooks', 'Homer']).to_a
Author.includes(:books).where(books: {title: 'Illiad'}).to_a
end
end
# == OUTPUT
# -- create_table(:authors)
# D, [2015-06-23T15:50:44.702986 #23785] DEBUG -- : (7.6ms) CREATE TABLE "authors" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "age" integer)
# -> 0.0184s
# -- create_table(:books)
# D, [2015-06-23T15:50:44.703782 #23785] DEBUG -- : (0.2ms) CREATE TABLE "books" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar, "sales" integer, "author_id" integer)
# -> 0.0006s
# Run options: --seed 34140
# # Running:
# D, [2015-06-23T15:50:44.813255 #23785] DEBUG -- : Author Load (0.1ms) SELECT "authors".* FROM "authors" WHERE "authors"."name" IN ('bell hooks', 'Homer')
# D, [2015-06-23T15:50:44.837158 #23785] DEBUG -- : SQL (0.2ms) SELECT "authors"."id" AS t0_r0, "authors"."name" AS t0_r1, "authors"."age" AS t0_r2, "books"."id" AS t1_r0, "books"."title" AS t1_r1, "books"."sales" AS t1_r2, "books"."author_id" AS t1_r3 FROM "authors" LEFT OUTER JOIN "books" ON "books"."author_id" = "authors"."id" WHERE "books"."title" = ? [["title", "Illiad"]]
# .
# Finished in 0.044347s, 22.5494 runs/s, 0.0000 assertions/s.
# 1 runs, 0 assertions, 0 failures, 0 errors, 0 skips |
@senny Usually it is the PS you are explicitly specifying this in your migration, so why not in your model? |
@aditya-kapoor granted, the |
[ci skip] correct for ActiveRecord::Associations::Preloader
Merged a modified version only expanding the |
@senny Thank you for your time and explanation. |
@aditya-kapoor thanks for being persistent and help us improve the docs ✨ |
[ci skip] correct for ActiveRecord::Associations::Preloader
I saw this example and something doesn't seemed right.