class ActiveScaffold::DataStructures::NestedInfo
Attributes
association[RW]
child_association[RW]
constrained_fields[RW]
parent_id[RW]
parent_model[RW]
parent_scaffold[RW]
Public Class Methods
get(model, params)
click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 3 def self.get(model, params) nested_info = {} begin nested_info[:name] = params[:association].to_sym nested_info[:parent_scaffold] = "#{params[:parent_scaffold].to_s.camelize}Controller".constantize nested_info[:parent_model] = nested_info[:parent_scaffold].active_scaffold_config.model nested_info[:parent_id] = params[nested_info[:parent_model].name.foreign_key] if nested_info[:parent_id] ActiveScaffold::DataStructures::NestedInfo.new(model, nested_info) end rescue ActiveScaffold::ControllerNotFound nil end end
new(model, nested_info)
click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 20 def initialize(model, nested_info) @parent_model = nested_info[:parent_model] @parent_id = nested_info[:parent_id] @parent_scaffold = nested_info[:parent_scaffold] @association = @parent_model.association_reflection(nested_info[: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 44 def belongs_to? association[:type] == :many_to_one end
default_sorting()
click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 56 def default_sorting association[:order] end
habtm?()
click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 40 def habtm? association[:type] == :many_to_many end
has_one?()
click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 48 def has_one? association[:type] == :one_to_one end
name()
click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 36 def name association[:name] end
parent_scope()
click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 32 def parent_scope parent_model[parent_id] end
sorted?()
click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 52 def sorted? association.has_key? :order end
to_params()
click to toggle source
# File lib/active_scaffold/data_structures/nested_info.rb, line 28 def to_params {:parent_scaffold => parent_scaffold.controller_path, :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 62 def iterate_model_associations(model) @constrained_fields = [] @constrained_fields << association[:key] unless belongs_to? model.association_reflections.each do |ass_name, ass_properties| if !ass_properties[:type] == :many_to_one && association[:key] == ass_properties[:class_name].foreign_key constrained_fields << ass_name @child_association = ass_properties if ass_properties.associated_class == @parent_model end if association[:key] == ass_properties[:key] # show columns for has_many and has_one child associationes constrained_fields << ass_name if ass_properties[:type] == :many_to_one @child_association = ass_properties if ass_properties.associated_class == @parent_model end end end