Sha256: 0cb3171c497e74eb27e989c46ef19ab998de55e2088e897418e7a8b870ed3bc0
Contents?: true
Size: 710 Bytes
Versions: 2
Compression:
Stored size: 710 Bytes
Contents
module Para module AttributeField class BelongsToField < RelationField register :belongs_to, self field_option :collection, :relation_options def field_name reflection.name end def value_for(instance) if (resource = instance.send(name)) resource_name(resource) end end def relation_options reflection.klass.all end def parse_input(params, resource) if (id = params[reflection.foreign_key].presence) && !reflection.klass.exists?(id: id) on_the_fly_creation(id) do |resource| params[reflection.foreign_key] = resource.id end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
para-0.7.1 | lib/para/attribute_field/belongs_to.rb |
para-0.7.0 | lib/para/attribute_field/belongs_to.rb |