Class Index [+]

Quicksearch

Sequel::Plugins::ManyThroughMany::DatasetMethods

Private Instance Methods

many_through_many_association_filter_expression(op, ref, obj) click to toggle source

Use a subquery to filter rows to those related to the given associated object

     # File lib/sequel/plugins/many_through_many.rb, line 245
245:         def many_through_many_association_filter_expression(op, ref, obj)
246:           lpks = ref[:left_primary_keys]
247:           lpks = lpks.first if lpks.length == 1
248:           lpks = ref.qualify(model.table_name, lpks)
249:           edges = ref.edges
250:           first, rest = edges.first, edges[1..1]
251:           last = edges.last
252:           ds = model.db[first[:table]].select(*Array(ref.qualify(first[:table], first[:right])))
253:           rest.each{|e| ds = ds.join(e[:table], e.fetch(:only_conditions, (Array(e[:right]).zip(Array(e[:left])) + e[:conditions])), :table_alias=>ds.unused_table_alias(e[:table]), &e[:block])}
254:           last_alias = if rest.empty?
255:             first[:table]
256:           else
257:             last_join = ds.opts[:join].last
258:             last_join.table_alias || last_join.table
259:           end
260:           meths = ref.right_primary_keys
261:           meths = ref.qualify(obj.model.table_name, meths) if obj.is_a?(Sequel::Dataset)
262:           exp = association_filter_key_expression(ref.qualify(last_alias, Array(ref.final_edge[:left])), meths, obj)
263:           if exp == SQL::Constants::FALSE
264:             association_filter_handle_inversion(op, exp, Array(lpks))
265:           else
266:             ds = ds.where(exp).exclude(SQL::BooleanExpression.from_value_pairs(ds.opts[:select].zip([]), :OR))
267:             association_filter_handle_inversion(op, SQL::BooleanExpression.from_value_pairs(lpks=>ds), Array(lpks))
268:           end
269:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.