Class Criteria::TableAlias
In: lib/table_alias.rb
Parent: Object

Superclass for classes that can contain joins (Query and Join) and are therefore associated with a database table.

Methods

Attributes

alias  [R] 
joins  [R] 
model_class  [R]  the class of the ActiveRecord model represented by this TableAlias
query  [R]  the root query to which this TableAlias belongs

Public Instance methods

[Source]

    # File lib/table_alias.rb, line 17
17:     def join(attribute, options={}, &block)
18:       
19:       attribute = attribute.to_s
20:       
21:       new_join = Join.new(attribute, self)
22:       (@joins ||= []) << new_join
23:       (@joins_hash ||= {})[attribute] = new_join
24:       
25:       join_alias = (options[:as] || attribute).intern
26: 
27:       # we cannot add a join if a method with that name already exists
28:       if respond_to? join_alias
29:         raise "Invalid join name. A method #{join_alias} already exists. Use :as when defining the join"
30:       end
31:       
32:       add new_join
33:       
34:       yield new_join if block_given?
35:       
36:       new_join
37:     end

[Source]

    # File lib/table_alias.rb, line 39
39:     def method_missing name, *args
40:       return @joins_hash[name] if @joins_hash && @joins_hash[name] 
41:       join name, *args
42:     end

[Source]

    # File lib/table_alias.rb, line 44
44:     def table_alias
45:       self
46:     end

[Validate]