On Tuesday, December 15, 2015 at 12:56:49 PM UTC-8, [email protected] wrote: > > Hello, I'll explain my question on example. Imagine we have two associated > models > > class Application < Sequel::Model > one_to_many :screens > end > > class Screen < Sequel:Model > many_to_one :application > end > > Nothing special here. So now to the question, examples again: > > > Application[0].screens[0].application.name > (0.002000s) SELECT * FROM "applications" WHERE "id" = 1 > (0.002000s) SELECT * FROM "screens" WHERE ("screens"."application_id" = 1) > => "Foo" > > Makes sense, there's no need to load application again to get its name. > But: > > > Application[0].screens_dataset.all[0].application.name > > (0.001000s) SELECT * FROM "applications" WHERE "id" = 1 > (0.002000s) SELECT * FROM "screens" WHERE ("screens"."application_id" = 1) > (0.001000s) SELECT * FROM "applications" WHERE "id" = 1 > => "Foo" > > Thats the part I don't understand. Why is application loaded again? Its > producing 1+n queries, sure I can use eager loading to load application for > every screen, but it will again produce one more SQL call to load same > application. >
If you use the dataset methods, no caching is done, so this is expected. If you want caching to be done, you probably want to use the association method, optionally passing a block to it. Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
