Sha256: 088642a659012d346d81f68a1978ba71d2afc7e216ba1cdbe36f862f4add0f3c
Contents?: true
Size: 1.25 KB
Versions: 187
Compression:
Stored size: 1.25 KB
Contents
module Lalala::Pages::PathHandler extend ActiveSupport::Concern module ClassMethods def ct_scoped_to_path(path, parent_constraint) if respond_to?(:translated?) and !translated?(name_sym) return super(path, parent_constraint) end path = path.is_a?(Enumerable) ? path.dup : [path] # make scope writable scope = scoped.readonly(false) # restrict by top scope = scope.joins(<<-SQL) INNER JOIN #{translations_table_name} AS t_ ON #{quoted_table_name}.id = t_.#{class_name.foreign_key} SQL scope = scope.where("t_.#{quoted_name_column} = #{ct_quote(path.last)}") path[0..-2].reverse.each_with_index do |ea, idx| subtable = idx == 0 ? quoted_table_name : "p#{idx - 1}" scope = scope.joins(<<-SQL) INNER JOIN #{quoted_table_name} AS p#{idx} ON p#{idx}.id = #{subtable}.#{parent_column_name} INNER JOIN #{translations_table_name} AS t#{idx} ON p#{idx}.id = t#{idx}.#{class_name.foreign_key} SQL scope = scope.where("t#{idx}.#{quoted_name_column} = #{ct_quote(ea)}") end root_table_name = path.size > 1 ? "p#{path.size - 2}" : quoted_table_name scope.where("#{root_table_name}.#{parent_constraint}") end end end
Version data entries
187 entries across 187 versions & 1 rubygems