If a prepared statement can be used to load the associated objects, execute it to retrieve them. Otherwise, fall back to the default implementation.
# File lib/sequel/plugins/prepared_statements_associations.rb, line 73 73: def _load_associated_objects(opts, dynamic_opts={}) 74: if !opts.can_have_associated_objects?(self) || dynamic_opts[:callback] || (ps = opts[:prepared_statement]) == false 75: super 76: else 77: if bv = association_bound_variables(opts) 78: (ps || association_prepared_statement(opts)).call(bv) 79: else 80: super 81: end 82: end 83: end
Return a bound variable hash that maps the keys in ks (qualified by the table) to the values of the results of sending the methods in vs.
# File lib/sequel/plugins/prepared_statements_associations.rb, line 41 41: def association_bound_variable_hash(table, ks, vs) 42: Hash[*ks.zip(vs).map{|k, v| [:"#{table}.#{k}", send(v)]}.flatten] 43: end
Given an association reflection, return a bound variable hash for the given association for this instance’s values.
# File lib/sequel/plugins/prepared_statements_associations.rb, line 47 47: def association_bound_variables(opts) 48: case opts[:type] 49: when :many_to_one 50: association_bound_variable_hash(opts.associated_class.table_name, opts.primary_keys, opts[:keys]) 51: when :one_to_many 52: association_bound_variable_hash(opts.associated_class.table_name, opts[:keys], opts[:primary_keys]) 53: when :many_to_many 54: association_bound_variable_hash(opts.join_table_alias, opts[:left_keys], opts[:left_primary_keys]) 55: when :many_through_many 56: association_bound_variable_hash(opts.final_reverse_edge[:alias], Array(opts[:left_key]), opts[:left_primary_keys]) 57: end 58: end
Given an association reflection, return and cache a prepared statement for this association such that, given appropriate bound variables, the prepared statement will work correctly for any instance.
# File lib/sequel/plugins/prepared_statements_associations.rb, line 63 63: def association_prepared_statement(opts) 64: opts.send(:cached_fetch, :prepared_statement) do 65: ps = _associated_dataset(opts, {}).unbind.first.prepare(opts.returns_array? ? :select : :first, :"smpsap_#{NEXT.call}") 66: ps.log_sql = true 67: ps 68: end 69: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.