closure_tree icon indicating copy to clipboard operation
closure_tree copied to clipboard

Loss of namespace when using Accessing Data methods

Open Zlatov opened this issue 2 years ago • 1 comments

# Gemfile.lock
  …
  closure_tree (7.4.0)
  …

I managed to save the namespace (Admin::) for the parent method with the following code:

# app/models/catalog.rb
class Catalog < ApplicationRecord
  has_closure_tree dependent: nil
end

# app/models/admin/catalog.rb
class Admin::Catalog < Catalog
  belongs_to :parent,
    class_name: '::Admin::Catalog',
    optional: true
end

Console, works as expected:

|> Admin::Catalog.last.parent => #<Admin::Catalog:0x00007ff2250a2d18

However, I need any help in order to bypass other methods, for example:

|> Admin::Catalog.last.self_and_ancestors => [#<Catalog:0x00007ff22a4c7790

Zlatov avatar Jun 03 '23 11:06 Zlatov

I guess the best solution would be:

# app/models/catalog.rb
class Catalog < ApplicationRecord
  include BaseBehaviorConcern

  has_closure_tree dependent: nil
end

# app/models/admin/catalog.rb
class Admin::Catalog < ApplicationRecord
  include BaseBehaviorConcern

  has_closure_tree dependent: nil
end

Use module connection instead of inheritance?

Zlatov avatar Jun 03 '23 13:06 Zlatov