Sha256: 8505a03c043c8e3ad2a8d1da1785757ca9226bd0c8db69e1a894256c820827a0
Contents?: true
Size: 901 Bytes
Versions: 27
Compression:
Stored size: 901 Bytes
Contents
module RailsOps module ModelMixins module VirtualHasOne extend ActiveSupport::Concern module ClassMethods # TODO: Passing type Fixnum currently requires a monkey-patch of ActiveType. # This would need to be changed when releasing this functionality as a Gem. # See config/initializers/patch_active_type.rb and # https://github.com/remofritzsche/active_type/commit/fb8c2cb4cccaaec # # TODO: Document. def virtual_has_one(name, base_class, required: false, default: nil, type: Integer) fk = "#{name}_id" attribute fk, type, default: default if required validates fk, presence: true end belongs_to name, anonymous_class: base_class, foreign_key: fk, class_name: base_class.name return reflect_on_association(name) end end end end end
Version data entries
27 entries across 27 versions & 1 rubygems