Module: MagicLocales::Association::ClassMethods

Defined in:
lib/app/models/magic_locales/association.rb

Overview

C L A S S - M E T H O D S # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

Instance Method Summary collapse

Instance Method Details

#has_languagesObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/app/models/magic_locales/association.rb', line 25

def has_languages
  # send :include, InstanceMethods
  
  has_many  :spoken_languages, 
                as:         :owner, 
                class_name: "MagicLocales::Language", 
                dependent: :destroy
  
  has_many  :foreign_languages, 
                -> { where.not(level: 'native') }, 
                as:         :owner, 
                class_name: "MagicLocales::Language", 
                dependent:  :destroy
  
  has_many  :native_languages, 
                -> { where(level: 'native') }, 
                as:         :owner, 
                class_name: "MagicLocales::Language", 
                dependent:  :destroy
  
  accepts_nested_attributes_for :spoken_languages,  allow_destroy: true,    reject_if: :all_blank
end

#has_one_languageObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/app/models/magic_locales/association.rb', line 12

def has_one_language
  # send :include, InstanceMethods
  
  has_one   :language, 
                -> { where(level: 'native', default: true) }, 
                as:         :owner, 
                class_name: "MagicLocales::Language", 
                dependent:  :destroy
  
  accepts_nested_attributes_for :language,          allow_destroy: true,    reject_if: :all_blank
end