Sha256: 705ecd59a9f797bedd185295b4aac44fb7991f76cb01891a14aa98dd81c61007

Contents?: true

Size: 593 Bytes

Versions: 9

Compression:

Stored size: 593 Bytes

Contents

require 'fiona7/attribute_writers/attribute_writer'

module Fiona7
  module AttributeWriters
    class ReferencelistAsLinklist < AttributeWriter
      def call(value, claimed_type=nil)
        # FIXME: use a repository to improve performance
        ids = (value || []).map(&:to_s)
        if ids.empty?
          self.obj.set(self.attr_name, [])
        else
          objects_map = Hash[self.klass.where(obj_id: ids).map {|o| [o.id.to_s, o]}]
          objects = ids.map {|id| objects_map[id] }.compact
          self.obj.set(self.attr_name, objects)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
infopark_fiona7-1.6.1.1.5 lib/fiona7/attribute_writers/referencelist_as_linklist.rb
infopark_fiona7-1.6.1.1.1 lib/fiona7/attribute_writers/referencelist_as_linklist.rb
infopark_fiona7-1.6.1.1.0 lib/fiona7/attribute_writers/referencelist_as_linklist.rb
infopark_fiona7-1.5.5.5.1 lib/fiona7/attribute_writers/referencelist_as_linklist.rb
infopark_fiona7-1.5.5.5.0 lib/fiona7/attribute_writers/referencelist_as_linklist.rb
infopark_fiona7-1.5.5.4.1 lib/fiona7/attribute_writers/referencelist_as_linklist.rb
infopark_fiona7-1.5.5.4.0 lib/fiona7/attribute_writers/referencelist_as_linklist.rb
infopark_fiona7-1.5.5.3.1 lib/fiona7/attribute_writers/referencelist_as_linklist.rb
infopark_fiona7-1.5.4.3.0 lib/fiona7/attribute_writers/referencelist_as_linklist.rb