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
#belongs_to?, get, #new_instance?, #plural_association?, #singular_association?
Constructor Details
Returns a new instance of NestedInfoAssociation.
72
73
74
75
76
77
78
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 72
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
#default_sorting ⇒ Object
121
122
123
124
125
126
127
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 121
def default_sorting
if association.options[:order] association.options[:order]
elsif association.respond_to?(:scope) association.klass.class_eval(&association.scope).values[:order] if association.scope.is_a? Proc
end
end
|
#habtm? ⇒ Boolean
86
87
88
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 86
def habtm?
association.macro == :has_and_belongs_to_many
end
|
#has_many? ⇒ Boolean
82
83
84
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 82
def has_many?
association.macro == :has_many
end
|
#has_one? ⇒ Boolean
92
93
94
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 92
def has_one?
association.macro == :has_one
end
|
#readonly? ⇒ Boolean
113
114
115
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 113
def readonly?
association.options[:readonly]
end
|
#readonly_through_association?(columns) ⇒ Boolean
A through association with has_one or has_many as source association create cannot be called in nested through associations, and not-nested through associations unless create columns include through reflection of reverse association e.g. customer -> networks -> firewall, reverse is firewall -> network -> customer, firewall can be created if create columns include network
101
102
103
104
105
106
107
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 101
def readonly_through_association?(columns)
return false unless through_association?
return true if association.through_reflection.options[:through]
association.source_reflection.macro != :belongs_to && (
!child_association || !columns.include?(child_association.through_reflection.name)
)
end
|
#sorted? ⇒ Boolean
117
118
119
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 117
def sorted?
association.options.key? :order
end
|
#through_association? ⇒ Boolean
109
110
111
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 109
def through_association?
association.options[:through]
end
|
#to_params ⇒ Object
129
130
131
|
# File 'lib/active_scaffold/data_structures/nested_info.rb', line 129
def to_params
super.merge(:association => @association.name, :assoc_id => parent_id)
end
|