lib/piglet/field/reference.rb in piglet-0.2.5 vs lib/piglet/field/reference.rb in piglet-0.3.0

- old
+ new

@@ -8,20 +8,17 @@ def initialize(name, relation=nil, options=nil) options ||= {} @name, @parent = name, relation @explicit_ancestry = options[:explicit_ancestry] || false @type = options[:type] + @predecessors = [relation] unless relation.nil? end def simple? true end - - def field(name) - Reference.new(name, self, :explicit_ancestry => true) - end - + def method_missing(name, *args) if name.to_s =~ /^\w+$/ && args.empty? field(name) else super @@ -30,15 +27,16 @@ def [](n) field("\$#{n}") end - def to_s + def to_s(inner=false) if @explicit_ancestry if @parent.respond_to?(:alias) "#{@parent.alias}.#{@name.to_s}" else - "#{@parent}.#{@name.to_s}" + expr = if inner then @parent.field_alias else @parent end + "#{expr}.#{@name.to_s}" end else @name.to_s end end \ No newline at end of file