Sha256: 867861e441c582d75ae93c13f63373323cee9f4016308f2bf3fba8da8c1fe74e
Contents?: true
Size: 1011 Bytes
Versions: 8
Compression:
Stored size: 1011 Bytes
Contents
# frozen_string_literal: true module RailsAdmin module Adapters module Mongoid module ObjectExtension def self.extended(object) object.associations.each do |name, association| association = Association.new(association, object.class) case association.macro when :has_many unless association.autosave? object.singleton_class.after_create do send(name).each(&:save) end end when :has_one unless association.autosave? object.singleton_class.after_create do send(name)&.save end end object.instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{name}_id=(item_id) self.#{name} = (#{association.klass}.find(item_id) rescue nil) end RUBY end end end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems