Кэш перестройки драгоценных камней Rails Ancestry

Я использую gem ancestry в приложении Rails3.

Я пытаюсь изменить существующую модель с именами сайтов, чтобы использовать глубину кеша.

В документации сказано следующее:

:cache_depth           Cache the depth of each node in the 'ancestry_depth' column (default: false)
                   If you turn depth_caching on for an existing model:
                   - Migrate: add_column [table], :ancestry_depth, :integer, :default => 0
                   - Build cache: TreeNode.rebuild_depth_cache!

Я добавил миграцию.

Но я не понимаю, как выполнить - Build cache: TreeNode.rebuild_depth_cache!

Где мне это сделать?

Спасибо за вашу помощь!


person Reddirt    schedule 24.07.2014    source источник


Ответы (1)


Использование модели, которая имеет родословную. Пример:

class Site
  has_ancestry cache_depth: true
end

> Site.rebuild_depth_cache!
person Pierre-Louis Gottfrois    schedule 24.07.2014
comment
Использование консоли Rails. s = Site.new дает мне 2.0.0p353 :001 > s = Site.new => #<Site id: nil, name: nil, description: nil, type_id: nil, tenant_id: nil, created_at: nil, updated_at: nil, address1: nil, address2: nil, city: nil, state: nil, zipcode: nil, ancestry: nil, position: nil, ancestry_depth: 0> - person Reddirt; 24.07.2014
comment
s.rebuild_depth_cache! дает мне NoMethodError: undefined method rebuild_depth_cache!' для #‹Сайт:0x007fa000800618›` - person Reddirt; 24.07.2014
comment
Спасибо за вашу помощь! - person Reddirt; 24.07.2014
comment
Измените свой ответ, включив в него: has_ancestry cache_depth: true - person Reddirt; 26.07.2014