@@ -31,6 +31,7 @@ class Classification < ApplicationRecord
3131 scope :is_category , -> { where ( :parent_id => nil ) }
3232 scope :is_entry , -> { where . not ( :parent_id => nil ) }
3333
34+ # TODO: move over to joins(:parent) or preload(:parent) - need something that works well with load()
3435 scope :with_writable_parents , -> { includes ( :parent ) . where ( :parents_classifications => { :read_only => false } ) }
3536
3637 DEFAULT_NAMESPACE = "/managed" . freeze
@@ -211,13 +212,13 @@ def self.create_category!(options)
211212 end
212213
213214 def self . categories ( region_id = my_region_number , ns = DEFAULT_NAMESPACE )
214- cats = is_category . in_region ( region_id ) . includes ( :tag , :children )
215+ cats = is_category . in_region ( region_id ) . preload ( :tag , :children )
215216 cats . select { |c | c . ns == ns }
216217 end
217218
218219 def self . category_names_for_perf_by_tag ( region_id = my_region_number , ns = DEFAULT_NAMESPACE )
219220 in_region ( region_id ) . is_category . where ( :perf_by_tag => true )
220- . includes ( :tag )
221+ . preload ( :tag )
221222 . collect { |c | c . name if c . tag2ns ( c . tag . name ) == ns }
222223 . compact
223224 end
@@ -513,7 +514,7 @@ def self.add_entries_from_hash(cat, entries)
513514 def validate_uniqueness_on_tag_name
514515 tag_name = Classification . name2tag ( name , parent , ns )
515516 exist_scope = Classification . default_scoped
516- . includes ( :tag )
517+ . left_outer_joins ( :tag )
517518 . where ( :tags => { :name => tag_name } )
518519 . merge ( Tag . in_region ( region_id ) )
519520 exist_scope = exist_scope . where . not ( :id => id ) unless new_record?
0 commit comments