Sha256: 8b04a28c8161a36d95bef4f768d64d6a4cd4551c6a247e44c07420eb7139ba9e

Contents?: true

Size: 993 Bytes

Versions: 16

Compression:

Stored size: 993 Bytes

Contents

#------------------------------------------------------------------------------
module DmCore
  module Concerns
    module HasCustomFields
      extend ActiveSupport::Concern

      included do

        has_many  :custom_fields, as: :owner, dependent: :destroy
        accepts_nested_attributes_for :custom_fields

        # Given an object that defines all the custom fields, builds any missing fields
        # onto the custom_fields association.
        #------------------------------------------------------------------------------
        def build_missing_fields(defining_object)
          existing_def_ids   = custom_fields.map(&:custom_field_def_id) # can't use pluck
          missing_field_defs = defining_object.custom_field_defs.reject {|x| existing_def_ids.include? x.id}
          missing_field_defs.each do |field_def|
            custom_fields.build(custom_field_def_id: field_def.id)
          end
        end
      end

      module ClassMethods
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
dm_core-4.2.3.10 app/models/dm_core/concerns/has_custom_fields.rb
dm_core-4.2.3.9 app/models/dm_core/concerns/has_custom_fields.rb
dm_core-4.2.3.8 app/models/dm_core/concerns/has_custom_fields.rb
dm_core-4.2.3.7 app/models/dm_core/concerns/has_custom_fields.rb
dm_core-4.2.3.6 app/models/dm_core/concerns/has_custom_fields.rb
dm_core-4.2.3.5 app/models/dm_core/concerns/has_custom_fields.rb
dm_core-4.2.3.4 app/models/dm_core/concerns/has_custom_fields.rb
dm_core-4.2.3.3 app/models/dm_core/concerns/has_custom_fields.rb
dm_core-4.2.3.2 app/models/dm_core/concerns/has_custom_fields.rb
dm_core-4.2.3.1 app/models/dm_core/concerns/has_custom_fields.rb
dm_core-4.2.3 app/models/dm_core/concerns/has_custom_fields.rb
dm_core-4.2.2.3 app/models/dm_core/concerns/has_custom_fields.rb
dm_core-4.2.2.2 app/models/dm_core/concerns/has_custom_fields.rb
dm_core-4.2.2.1 app/models/dm_core/concerns/has_custom_fields.rb
dm_core-4.2.2 app/models/dm_core/concerns/has_custom_fields.rb
dm_core-4.2.1.5 app/models/dm_core/concerns/has_custom_fields.rb