Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loss of namespace when using Accessing Data methods #422

Open
Zlatov opened this issue Jun 3, 2023 · 1 comment
Open

Loss of namespace when using Accessing Data methods #422

Zlatov opened this issue Jun 3, 2023 · 1 comment

Comments

@Zlatov
Copy link

Zlatov commented Jun 3, 2023

# 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
Copy link
Author

Zlatov commented Jun 3, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant