Class: Para::AttributeField::RelationField
Instance Attribute Summary
Attributes inherited from Base
#field_method, #field_type, #model, #name, #options, #type
Instance Method Summary
collapse
Methods inherited from Base
#attribute_column_path, #determine_name_and_field_method!, #excerptable_value?, #field_name, field_option, #field_options, field_types, #initialize, #parse_input, register, #searchable?, #type?, #value_for
Instance Method Details
#foreign_key ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/para/attribute_field/relation.rb', line 10
def foreign_key
@foreign_key ||= reflection && case reflection.macro
when :belongs_to then reflection.foreign_key
when :has_one then :"#{ reflection.name }_id"
when :has_many then :"#{ reflection.name.to_s.singularize }_ids"
end
end
|
#polymorphic_through_reflection? ⇒ Boolean
30
31
32
|
# File 'lib/para/attribute_field/relation.rb', line 30
def polymorphic_through_reflection?
!!(through_relation && reflection.source_reflection.options[:polymorphic])
end
|
#reflection ⇒ Object
6
7
8
|
# File 'lib/para/attribute_field/relation.rb', line 6
def reflection
@reflection ||= model.reflect_on_association(name)
end
|
#through_reflection ⇒ Object
22
23
24
|
# File 'lib/para/attribute_field/relation.rb', line 22
def through_reflection
@through_reflection ||= through_relation && model.reflect_on_association(through_relation)
end
|
#through_relation ⇒ Object
18
19
20
|
# File 'lib/para/attribute_field/relation.rb', line 18
def through_relation
@through_relation ||= reflection.options[:through]
end
|
#through_relation_source_foreign_key ⇒ Object
26
27
28
|
# File 'lib/para/attribute_field/relation.rb', line 26
def through_relation_source_foreign_key
@through_relation_source_foreign_key ||= reflection.source_reflection.foreign_key
end
|