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

Using namespaced classes does not work #391

Open
enricodvn opened this issue May 9, 2024 · 3 comments
Open

Using namespaced classes does not work #391

enricodvn opened this issue May 9, 2024 · 3 comments

Comments

@enricodvn
Copy link

When using this gem with namespaced classes, this gem breaks.

Ex:

class ModuleA::ModuleB::ClassA < ApplicationRecord
  has_paper_trail

  include Monetizable

  # Relationships
  belongs_to :class_c, class_name: 'ModuleA::ClassC'
  belongs_to :class_d, -> { includes(:class_e) }, class_name: 'ModuleC::ClassD'

  counter_culture [:class_d, :class_e], column_name: "orders_count"

throws:

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  invalid reference to FROM-clause entry for table...

HINT:  Perhaps you meant to reference the table alias "modulec_class_d".

Whenever I call ModuleA::ModuleB::ClassA .counter_culture_fix_counts

@enricodvn
Copy link
Author

Just to add mode context, modulo A has this table_prefix:

module ModuleA

  def self.table_name_prefix
    'modulea.'
  end
end

Something like explained here:
https://icelandcheng.medium.com/ruby-on-rails-using-table-name-prefix-and-namespace-to-organize-models-a08199deaa69

Also, I have seems this issue in some other libs, like:
RolifyCommunity/rolify#75

They seems to have fixed it somehow.

@magnusvk
Copy link
Owner

magnusvk commented May 9, 2024

Can you open a PR with a failing test case for this? I believe you it's failing but it's hard to debug with just that error, without a stack trace etc. I'd love a PR with a fix, too, if you can identify that.

@enricodvn
Copy link
Author

Alright, I will work on it!

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

2 participants