Method: Sequel::Model::Associations::DatasetMethods#eager_graph_with_options
- Defined in:
- lib/sequel/model/associations.rb
#eager_graph_with_options(associations, opts = OPTS) ⇒ Object
Run eager_graph with some options specific to just this call. Unlike eager_graph, this takes the associations as a single argument instead of multiple arguments.
Options:
- :join_type
-
Override the join type specified in the association
- :limit_strategy
-
Use a strategy for handling limits on associations. Appropriate :limit_strategy values are:
- true
-
Pick the most appropriate based on what the database supports
- :distinct_on
-
Force use of DISTINCT ON stategy (*_one associations only)
- :correlated_subquery
-
Force use of correlated subquery strategy (one_to_* associations only)
- :window_function
-
Force use of window function strategy
- :ruby
-
Don’t modify the SQL, implement limits/offsets with array slicing
This can also be a hash with association name symbol keys and one of the above values, to use different strategies per association.
The default is the :ruby strategy. Choosing a different strategy can make your code significantly slower in some cases (perhaps even the majority of cases), so you should only use this if you have benchmarked that it is faster for your use cases.
3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 |
# File 'lib/sequel/model/associations.rb', line 3315 def (associations, opts=OPTS) return self if associations.empty? opts = opts.dup unless opts.frozen? associations = [associations] unless associations.is_a?(Array) ds = if eg = @opts[:eager_graph] eg = eg.dup [:requirements, :reflections, :reciprocals, :limits].each{|k| eg[k] = eg[k].dup} eg[:local] = opts ds = clone(:eager_graph=>eg) ds.eager_graph_associations(ds, model, ds.opts[:eager_graph][:master], [], *associations) else # Each of the following have a symbol key for the table alias, with the following values: # :reciprocals :: the reciprocal value to use for this association # :reflections :: AssociationReflection instance related to this association # :requirements :: array of requirements for this association # :limits :: Any limit/offset array slicing that need to be handled in ruby land after loading opts = {:requirements=>{}, :master=>alias_symbol(first_source), :reflections=>{}, :reciprocals=>{}, :limits=>{}, :local=>opts, :cartesian_product_number=>0, :row_proc=>row_proc} ds = clone(:eager_graph=>opts) ds = ds.eager_graph_associations(ds, model, ds.opts[:eager_graph][:master], [], *associations).naked end ds.opts[:eager_graph].freeze ds.opts[:eager_graph].each_value{|v| v.freeze if v.is_a?(Hash)} ds end |