class ActiveScaffold::DataStructures::NestedInfoAssociation

Public Class Methods

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

Public Instance Methods

belongs_to?() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 95
def belongs_to?
  association.belongs_to?
end
default_sorting() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 121
def default_sorting
  association.options[:order]
end
habtm?() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 91
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 87
def has_many?
  association.macro == :has_many 
end
has_one?() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 99
def has_one?
  association.macro == :has_one
end
name() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 83
def name
  self.association.name
end
readonly?() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 113
def readonly?
  association.options[:readonly]
end
readonly_through_association?() click to toggle source

A through association with has_one or has_many as source association create cannot be called in such through association

# File lib/active_scaffold/data_structures/nested_info.rb, line 105
def readonly_through_association?
  association.options[:through] && association.source_reflection.macro != :belongs_to
end
sorted?() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 117
def sorted?
  association.options.has_key? :order
end
through_association?() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 109
def through_association?
  association.options[:through]
end
to_params() click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 125
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 131
def iterate_model_associations(model)
  @constrained_fields = []
  constrained_fields << association.foreign_key.to_sym unless association.belongs_to?
  if reverse = association.reverse(model)
    @child_association = model.reflect_on_association(reverse)
    constrained_fields << @child_association.name unless @child_association == association
  end
end