Class: Para::AttributeField::RelationField

Inherits:
Base
  • Object
show all
Includes:
Helpers::ResourceName
Defined in:
lib/para/attribute_field/relation.rb

Direct Known Subclasses

BelongsToField, HasManyField

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

Constructor Details

This class inherits a constructor from Para::AttributeField::Base

Instance Method Details

#foreign_keyObject



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

Returns:

  • (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

#reflectionObject



6
7
8
# File 'lib/para/attribute_field/relation.rb', line 6

def reflection
  @reflection ||= model.reflect_on_association(name)
end

#through_reflectionObject



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_relationObject



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_keyObject



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