class ActiveScaffold::DataStructures::NestedInfoAssociation

Public Instance Methods

belongs_to?() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 104
def belongs_to?
  association.belongs_to?
end
default_sorting() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 124
def default_sorting
  association.options[:order]
end
habtm?() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 100
def habtm?
  association.macro == :has_and_belongs_to_many 
end
has_many?() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 96
def has_many?
  association.macro == :has_many 
end
has_one?() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 108
def has_one?
  association.macro == :has_one
end
name() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 92
def name
  self.association.name
end
readonly?() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 116
def readonly?
  association.options[:readonly]
end
sorted?() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 120
def sorted?
  association.options.has_key? :order
end
through_association?() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 112
def through_association?
  association.options[:through]
end
to_params() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 128
def to_params
  super.merge(:association => @association.name, :assoc_id => parent_id)
end

Protected Instance Methods

iterate_model_associations(model) click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 134
def iterate_model_associations(model)
  @constrained_fields = Set.new
  constrained_fields << association.foreign_key.to_sym unless association.belongs_to?
  model.reflect_on_all_associations.each do |current|
    if !current.belongs_to? && association != current && association.foreign_key.to_s == current.association_foreign_key.to_s
      constrained_fields << current.name.to_sym
      @child_association = current if current.klass == @parent_model
    end
    if association.foreign_key.to_s == current.foreign_key.to_s
      # show columns for has_many and has_one child associationes
      constrained_fields << current.name.to_sym if current.belongs_to?
      if association.options[:as] and current.options[:polymorphic]
        @child_association = current if association.options[:as].to_sym == current.name
      else
        @child_association = current if current.klass == @parent_model
      end
    end
  end
  @constrained_fields = @constrained_fields.to_a
end

Public Class Methods

new(model, nested_info) click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 86
def initialize(model, nested_info)
  super(model, nested_info)
  @association = parent_model.reflect_on_association(nested_info[:name])
  iterate_model_associations(model)
end