initialize a column if column is an association of the current model, the
entries are sorted either by a ruby-block (if a :method is defined to call
on the association-object), by :size (ruby-block, if its a
has_many association) or simply by the id (ORDER-SQL statement) if
columns is not an association, the entries are sorted by an ORDER-SQL
statement.
[Source]
160: def initialize( id, config_table, *args )
161: @id = id
162: @opts = *args || Hash.new(nil)
163: @method = @opts[:method]
164: @name = @opts[:name] || @id.to_s
165: @config_table = config_table
166:
167: @assoc = @config_table.assocs.find { |s| s.name.to_sym == @id.to_sym }
168:
169: @order = @opts[:sort]
170:
171:
172:
173: unless @order
174: if is_assoc?
175: if @method
176: @order = Proc.new { |a,b|
177: a.__send__( @id ).__send__( @method ).to_s <=> b.__send__( @id ).__send__( @method ).to_s
178: }
179:
180: else
181: @order = is_has_many_assoc? ? Proc.new { |a,b| a.__send__(@method).size <=> b.__send__(@method).size } :
182: "`#{assoc_table_name}`.`id`"
183: end
184: else
185: @order = "`#{@config_table.model.table_name}`.`#{@id}`"
186: end
187: end
188:
189: end