diff options
Diffstat (limited to 'app/models/node.rb')
| -rw-r--r-- | app/models/node.rb | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/app/models/node.rb b/app/models/node.rb index 2177f15..fc23dc1 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | class Node < ApplicationRecord | 1 | class Node < ApplicationRecord |
| 2 | # Mixins and Plugins | 2 | # Mixins and Plugins |
| 3 | acts_as_nested_set | 3 | include NestedTree |
| 4 | 4 | ||
| 5 | # Associations | 5 | # Associations |
| 6 | has_many :pages, -> { order("revision ASC") }, :dependent => :destroy | 6 | has_many :pages, -> { order("revision ASC") }, :dependent => :destroy |
| @@ -21,16 +21,6 @@ class Node < ApplicationRecord | |||
| 21 | validates_uniqueness_of :slug, :scope => :parent_id, :unless => -> { parent_id.nil? } | 21 | validates_uniqueness_of :slug, :scope => :parent_id, :unless => -> { parent_id.nil? } |
| 22 | validates_presence_of :parent_id, :unless => -> { Node.root.nil? } | 22 | validates_presence_of :parent_id, :unless => -> { Node.root.nil? } |
| 23 | 23 | ||
| 24 | validate :borders # This should never ever happen. | ||
| 25 | |||
| 26 | # Index for Fulltext Search | ||
| 27 | # define_index do | ||
| 28 | # indexes head.translations.title | ||
| 29 | # indexes slug | ||
| 30 | # indexes unique_name | ||
| 31 | # indexes head.translations.body | ||
| 32 | # end | ||
| 33 | |||
| 34 | # Class methods | 24 | # Class methods |
| 35 | 25 | ||
| 36 | # Returns a page for a given node. If no revision is supplied, it returns | 26 | # Returns a page for a given node. If no revision is supplied, it returns |
| @@ -254,10 +244,13 @@ class Node < ApplicationRecord | |||
| 254 | # Watch out recursion ahead! update_unique_name itself triggers this | 244 | # Watch out recursion ahead! update_unique_name itself triggers this |
| 255 | # after_save callback which invokes update_unique_name on its children. | 245 | # after_save callback which invokes update_unique_name on its children. |
| 256 | # Hopefully until no childrens occur | 246 | # Hopefully until no childrens occur |
| 247 | # | ||
| 248 | # Queries parent_id directly rather than the NestedTree#children | ||
| 249 | # association out of habit from the old awesome_nested_set-avoidance | ||
| 250 | # workaround - no longer strictly necessary now that children is | ||
| 251 | # equally safe, but left as-is since it already works correctly. | ||
| 257 | def update_unique_names_of_children | 252 | def update_unique_names_of_children |
| 258 | unless root? | 253 | unless root? |
| 259 | # Use parent_id-based traversal instead of lft/rgt descendants | ||
| 260 | # due to awesome_nested_set not refreshing parent lft/rgt in memory | ||
| 261 | Node.where(:parent_id => self.id).each do |child| | 254 | Node.where(:parent_id => self.id).each do |child| |
| 262 | child.reload | 255 | child.reload |
| 263 | child.update_unique_name | 256 | child.update_unique_name |
| @@ -265,10 +258,4 @@ class Node < ApplicationRecord | |||
| 265 | end | 258 | end |
| 266 | end | 259 | end |
| 267 | end | 260 | end |
| 268 | |||
| 269 | def borders | ||
| 270 | if lft && rgt && (lft > rgt) | ||
| 271 | errors.add("Fuck!. lft should never be smaller than rgt") | ||
| 272 | end | ||
| 273 | end | ||
| 274 | end | 261 | end |
