Sha256: d290260b49da262a611a0f760e75b963ef278988dcfe51762351f3cd1804347f

Contents?: true

Size: 782 Bytes

Versions: 2

Compression:

Stored size: 782 Bytes

Contents

module HasUuid
  module ActiveRecord
    module BelongsToAssociation
      extend ActiveSupport::Concern

      included do
        def replace_keys_with_uuid(record)
          if record.class.respond_to?(:has_uuid?) && record.class.has_uuid?
            if foreign_uuid_present?
              if record
                owner[reflection.foreign_uuid] = record[reflection.association_uuid_key(record.class)]
              else
                owner[reflections.foreign_uuid] = nil
              end
            end
          end
          replace_keys_without_uuid(record)
        end
        alias_method_chain :replace_keys, :uuid
      end

      def foreign_uuid_present?
        owner.class.columns.map(&:name).include?(reflection.foreign_uuid.to_s)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails_has_uuid-0.3.0 lib/has_uuid/active_record/belongs_to_association.rb
rails_has_uuid-0.2.0 lib/has_uuid/active_record/belongs_to_association.rb