# 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
# File lib/active_scaffold/data_structures/nested_info.rb, line 95 def belongs_to? association.belongs_to? end
# File lib/active_scaffold/data_structures/nested_info.rb, line 121 def default_sorting association.options[:order] end
# File lib/active_scaffold/data_structures/nested_info.rb, line 91 def habtm? association.macro == :has_and_belongs_to_many end
# File lib/active_scaffold/data_structures/nested_info.rb, line 87 def has_many? association.macro == :has_many end
# File lib/active_scaffold/data_structures/nested_info.rb, line 99 def has_one? association.macro == :has_one end
# File lib/active_scaffold/data_structures/nested_info.rb, line 83 def name self.association.name end
# File lib/active_scaffold/data_structures/nested_info.rb, line 113 def readonly? association.options[:readonly] end
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
# File lib/active_scaffold/data_structures/nested_info.rb, line 117 def sorted? association.options.has_key? :order end
# File lib/active_scaffold/data_structures/nested_info.rb, line 109 def through_association? association.options[:through] end
# File lib/active_scaffold/data_structures/nested_info.rb, line 125 def to_params super.merge(:association => @association.name, :assoc_id => parent_id) end
# 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