Sha256: 41671390a16362c8f90757be2716930e2df0d1eb0e569daecac633fd774eb92e
Contents?: true
Size: 759 Bytes
Versions: 47
Compression:
Stored size: 759 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 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 end end end
Version data entries
47 entries across 47 versions & 1 rubygems