Sha256: 8c5eda1ed52ec186c033a94a0f8a8861c854856240c8b33d88a3989c0ca374e2
Contents?: true
Size: 1.03 KB
Versions: 70
Compression:
Stored size: 1.03 KB
Contents
module ActiveFedora::Associations::Builder class BelongsTo < SingularAssociation #:nodoc: def self.macro :belongs_to end def self.valid_options(options) super + [:optional] end def self.valid_dependent_options [:destroy, :delete] end def self.validate_options(options) super raise "You must specify a predicate for #{name}" unless options[:predicate] raise ArgumentError, "Predicate must be a kind of RDF::URI" unless options[:predicate].is_a?(RDF::URI) end def self.define_validations(model, reflection) if reflection.options.key?(:required) reflection.options[:optional] = !reflection.options.delete(:required) end required = if reflection.options[:optional].nil? model.belongs_to_required_by_default else !reflection.options[:optional] end super if required model.validates_presence_of reflection.name, message: :required end end end end
Version data entries
70 entries across 70 versions & 1 rubygems