Giter Site home page Giter Site logo

Comments (3)

madeindjs avatar madeindjs commented on May 6, 2024 1

Corrected with this commit.

from api_on_rails.

madeindjs avatar madeindjs commented on May 6, 2024

Thre are two different includes:

  1. Product.includes(:user) this one is from Active Record and it loads relations Product#user
  2. 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.

notapatch avatar notapatch commented on May 6, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.