class ActiveScaffold::DataStructures::NestedInfoAssociation

Public Class Methods

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

Public Instance Methods

belongs_to?() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 73
def belongs_to?
  association.belongs_to?
end
default_sorting() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 93
def default_sorting
  association.options[:order]
end
habtm?() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 69
def habtm?
  association.macro == :has_and_belongs_to_many 
end
has_one?() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 77
def has_one?
  association.macro == :has_one
end
readonly?() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 81
def readonly?
  if association.options.has_key? :readonly
    association.options[:readonly]
  else
    association.options.has_key? :through
  end
end
sorted?() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 89
def sorted?
  association.options.has_key? :order
end

Protected Instance Methods

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