Comments (3)
Corrected with this commit.
from api_on_rails.
Thre are two different includes:
Product.includes(:user)
this one is from Active Record and it loads relationsProduct#user
options[:include] = [:user]
this one is from fast_jsonapi options
But it seem that code example does not include includes(:user)
. I added warning disappeared:
Started GET "/api/v1/products" for ::1 at 2021-01-24 08:57:41 +0100
(0.1ms) SELECT sqlite_version(*)
Processing by Api::V1::ProductsController#index as JSON
(0.2ms) SELECT COUNT(*) FROM "products"
↳ app/controllers/concerns/paginable.rb:9:in `get_links_serializer_options'
Product Load (0.2ms) SELECT "products".* FROM "products" LIMIT ? OFFSET ? [["LIMIT", 20], ["OFFSET", 0]]
↳ app/controllers/api/v1/products_controller.rb:17:in `index'
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" IN (?, ?, ?) [["id", 7], ["id", 8], ["id", 9]]
↳ app/controllers/api/v1/products_controller.rb:17:in `index'
(0.2ms) SELECT "products"."id" FROM "products" WHERE "products"."user_id" = ? [["user_id", 7]]
↳ app/controllers/api/v1/products_controller.rb:17:in `index'
(0.1ms) SELECT "products"."id" FROM "products" WHERE "products"."user_id" = ? [["user_id", 8]]
↳ app/controllers/api/v1/products_controller.rb:17:in `index'
(0.2ms) SELECT "products"."id" FROM "products" WHERE "products"."user_id" = ? [["user_id", 9]]
↳ app/controllers/api/v1/products_controller.rb:17:in `index'
Completed 200 OK in 50ms (Views: 2.4ms | ActiveRecord: 3.8ms | Allocations: 22119)
Can you try it and confirm that works?
from api_on_rails.
Yes, I got confused between the include
for the serialization and the includes
for the N+1 query.
On re-reading the section it now makes sense. Glad the code example is fixed as I would have checked my code against it when things didn't make sense.
Closing.
from api_on_rails.
Related Issues (20)
- Chapter 2 config/routes.rb listing 4-6 changes HOT 3
- Chapter 3: Build users - namespace nesting in book different from my generated code HOT 2
- Chapter 3 - Build users - phrase 'user who will display a user' HOT 3
- Chapter 4 - autoload_path HOT 3
- Chapter 4 Logged user HOT 3
- Image to embed not found in chapter 02 HOT 2
- Chapter 3 - missing permited param password_digest HOT 1
- Where's the source code? HOT 1
- @authentication = MockController.new OR @authentication = Authentication.new ? HOT 3
- Number of test assertions mentioned on the page 58 HOT 1
- Chapter 6 on Test sort products HOT 2
- Rails 5.2 switched to credentials HOT 3
- Mis-translation https://github.com/madeindjs/api_on_rails/blob/master/rails6/en/chapter07-placing-orders.adoc HOT 1
- Consider updating fast_jsonapi to jsonapi-serializer HOT 5
- It would be great if all the tests could be rewritten with RSpec HOT 1
- Serialize generator already adds attributes
- Broken link HOT 2
- Failure during a rake test because of wrong password attribute in test/models/user_test.rb HOT 2
- Chapter 6 Listing 88/89 tests ordering without being ordered
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from api_on_rails.