app/models/concerns/inflectionable.rb in iqvoc_inflectionals-2.9.0 vs app/models/concerns/inflectionable.rb in iqvoc_inflectionals-2.11.3
- old
+ new
@@ -6,13 +6,23 @@
attr_reader :inflectionals_attributes
after_save :overwrite_inflectionals!
after_save :create_default_inflectional
has_many :inflectionals,
- :class_name => "Inflectional::Base",
- :foreign_key => "label_id",
- :dependent => :destroy
+ class_name: "Inflectional::Base",
+ foreign_key: "label_id",
+ dependent: :destroy,
+ inverse_of: :label
+
+ # overwrite class method to query labels by all existing inflectionals
+ # instead of basic xl-label value attribute
+ def self.by_query_value(query)
+ Iqvoc::XLLabel.base_class
+ .references(:inflectionals)
+ .joins(:inflectionals)
+ .where('inflectionals.value ILIKE ?', query.mb_chars.downcase.to_s)
+ end
end
def endings
Inflectional::Base.for_language_and_code(language, inflectional_code)
end
@@ -50,10 +60,10 @@
end
end
def create_default_inflectional
# ensure a matching inflectional exists
- if value && inflectionals.where(:value => value).none?
+ if value && inflectionals.empty?
inflectionals.create(:value => value)
end
end
end