app/models/scribo/content.rb in scribo-1.0.40 vs app/models/scribo/content.rb in scribo-1.0.41
- old
+ new
@@ -3,11 +3,11 @@
require_dependency 'scribo/application_record'
module Scribo
# Represents any content in the system
class Content < ApplicationRecord
- has_ancestry(primary_key_format: /\A[\w\-]+(\/[\w\-]+)*\z/, counter_cache: true, cache_depth: true)
+ has_closure_tree
belongs_to :site, class_name: 'Site', foreign_key: 'scribo_site_id'
has_one_attached :asset
validate :post_path
validate :layout_cant_be_current_content
@@ -291,11 +291,11 @@
search_paths.concat(Scribo::Utility.variations_for_path(search_path))
search_paths << Scribo::Utility.switch_extension(search_path, 'link')
end
def store_full_path(force = false)
- if force || saved_changes.include?(:path) || saved_changes.include?(:ancestry)
+ if force || saved_changes.include?(:path) || saved_changes.include?(:parent_id)
if post?
result = categories.join('/') + '/'
result += date.strftime('%Y/%m/%d/') if date
result += path[11..-1]
elsif part_of_collection? && site.output_collection?(collection_name)
@@ -308,12 +308,12 @@
update_column(:full_path, result)
children.reload.each do |child|
child.store_full_path(true)
end
-
end
end
+
def tree_path
result = (ancestors.map(&:path) << path).join('/')
result = '/' + result unless result.start_with?('/')
result