Class: ActiveFedora::Associations::Builder::BelongsTo
  
  
  
Overview
  
  Constant Summary
  
  Constants inherited
     from Association
  Association::VALID_OPTIONS
  
    
      Class Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  
  define_accessors, define_constructors
  
  
  
  
  
  
  
  
  Methods inherited from Association
  add_destroy_callbacks, better_name, build, build_scope, check_dependent_options, create_reflection, define_accessors, define_callbacks, define_extensions, define_readers, define_writers, wrap_scope
  
    Class Method Details
    
      
  
  
    .define_validations(model, reflection)  ⇒ Object 
  
  
  
  
    
      
21
22
23
24
25
26
27
28
29
30
31
32
33 
     | 
    
      # File 'lib/active_fedora/associations/builder/belongs_to.rb', line 21
def self.define_validations(model, reflection)
  reflection.options[:optional] = !reflection.options.delete(:required) if reflection.options.key?(:required)
  required = if reflection.options[:optional].nil?
               model.belongs_to_required_by_default
             else
               !reflection.options[:optional]
             end
  super
  model.validates_presence_of reflection.name, message: :required if required
end
     | 
  
 
    
      
  
  
    .macro  ⇒ Object 
  
  
  
  
    
      
3
4
5 
     | 
    
      # File 'lib/active_fedora/associations/builder/belongs_to.rb', line 3
def self.macro
  :belongs_to
end 
     | 
  
 
    
      
  
  
    .valid_dependent_options  ⇒ Object 
  
  
  
  
    
      
11
12
13 
     | 
    
      # File 'lib/active_fedora/associations/builder/belongs_to.rb', line 11
def self.valid_dependent_options
  [:destroy, :delete]
end 
     | 
  
 
    
      
  
  
    .valid_options(options)  ⇒ Object 
  
  
  
  
    
      
7
8
9 
     | 
    
      # File 'lib/active_fedora/associations/builder/belongs_to.rb', line 7
def self.valid_options(options)
  super + [:optional]
end 
     | 
  
 
    
      
  
  
    .validate_options(options)  ⇒ Object 
  
  
  
  
    
      
15
16
17
18
19 
     | 
    
      # File 'lib/active_fedora/associations/builder/belongs_to.rb', line 15
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
     |