Class: ActiveScaffold::DataStructures::NestedInfoAssociation

Inherits:
NestedInfo show all
Defined in:
lib/active_scaffold/data_structures/nested_info.rb

Instance Attribute Summary

Attributes inherited from NestedInfo

#association, #child_association, #constrained_fields, #param_name, #parent_id, #parent_model, #parent_scaffold, #scope

Instance Method Summary collapse

Methods inherited from NestedInfo

get, #new_instance?, #plural_association?, #singular_association?

Constructor Details

#initialize(model, params) ⇒ NestedInfoAssociation

Returns a new instance of NestedInfoAssociation.



75
76
77
78
79
80
81
# 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

Instance Method Details

#belongs_to?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 95

def belongs_to?
  association.belongs_to?
end

#default_sortingObject



121
122
123
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 121

def default_sorting
  association.options[:order]
end

#habtm?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 91

def habtm?
  association.macro == :has_and_belongs_to_many 
end

#has_many?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 87

def has_many?
  association.macro == :has_many 
end

#has_one?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 99

def has_one?
  association.macro == :has_one
end

#nameObject



83
84
85
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 83

def name
  self.association.name
end

#readonly?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 113

def readonly?
  association.options[:readonly]
end

#readonly_through_association?Boolean

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

Returns:

  • (Boolean)


105
106
107
# 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?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 117

def sorted?
  association.options.has_key? :order
end

#through_association?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 109

def through_association?
  association.options[:through]
end

#to_paramsObject



125
126
127
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 125

def to_params
  super.merge(:association => @association.name, :assoc_id => parent_id)
end