Class: Para::AttributeField::BelongsToField
Instance Method Summary
collapse
#foreign_key, #polymorphic_through_reflection?, #reflection, #through_reflection, #through_relation, #through_relation_source_foreign_key
#resource_name
Instance Method Details
#field_name ⇒ Object
8
9
10
|
# File 'lib/para/attribute_field/belongs_to.rb', line 8
def field_name
reflection.name
end
|
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/para/attribute_field/belongs_to.rb', line 22
def parse_input(params, resource)
if reflection &&
(id = params[reflection.foreign_key].presence) &&
!reflection.klass.exists?(id: id)
then
on_the_fly_creation(id) do |resource|
params[reflection.foreign_key] = resource.id
end
end
end
|
#relation_options ⇒ Object
18
19
20
|
# File 'lib/para/attribute_field/belongs_to.rb', line 18
def relation_options
reflection.klass.all
end
|
#value_for(instance) ⇒ Object
12
13
14
15
16
|
# File 'lib/para/attribute_field/belongs_to.rb', line 12
def value_for(instance)
if (resource = instance.send(name))
resource_name(resource)
end
end
|