Sha256: 5b739a321f8ec0f627c050c9d4a6613886beba1a345cb2a5335d654e32c6c3ce
Contents?: true
Size: 1.15 KB
Versions: 1
Compression:
Stored size: 1.15 KB
Contents
# The core logic of this class is old Rails behaviour, replicated here because # their own alias logic has evolved, but I haven't yet found a way to make use # of it - and besides, this is only used to generate Thinking Sphinx's # configuration rarely - not in any web requests, so performance issues are less # critical here. class Joiner::JoinAliaser def self.call(join_root, alias_tracker) new(join_root, alias_tracker).call end def initialize(join_root, alias_tracker) @join_root = join_root @alias_tracker = alias_tracker end def call join_root.each_children do |parent, child| child.table = table_aliases_for(parent, child).first end end private attr_reader :join_root, :alias_tracker def table_aliases_for(parent, node) node.reflection.chain.map { |reflection| alias_tracker.aliased_table_for( reflection.table_name, table_alias_for(reflection, parent, reflection != node.reflection), reflection.klass.type_caster ) } end def table_alias_for(reflection, parent, join) name = reflection.alias_candidate(parent.table_name) join ? "#{name}_join" : name end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
joiner-0.6.0 | lib/joiner/join_aliaser.rb |