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

"uninitialized constant" in case of "namespaced" models #204

Open
jhovad opened this issue Jul 15, 2019 · 1 comment
Open

"uninitialized constant" in case of "namespaced" models #204

jhovad opened this issue Jul 15, 2019 · 1 comment

Comments

@jhovad
Copy link

jhovad commented Jul 15, 2019

I try to use acts_as_tenant on SpinaCMS models. Those are all under Spina:: ... I probably don't have skill to fix it properly, but there is my super monkey patch of this line:

association_class = a.options[:class_name].nil? ? ("Spina::"+a.name.to_s.classify).constantize : a.options[:class_name].constantize

I believe it can be written much better..?

association_class = a.options[:class_name].nil? ? a.name.to_s.classify.constantize : a.options[:class_name].constantize

PS: unfortunately when I run the console:

> Spina::Page.reflect_on_all_associations(:belongs_to).first
=> #<ActiveRecord::Reflection::BelongsToReflection:0x00007f8fe5593798 @name=:resource, @scope=nil, @options={:optional=>true}, @active_record=Spina::Page(id: integer, show_in_menu: boolean, slug: string, deletable: boolean, created_at: datetime, updated_at: datetime, name: string, skip_to_first_child: boolean, view_template: string, layout_template: string, draft: boolean, link_url: string, ancestry: string, position: integer, active: boolean, resource_id: integer, account_id: integer), @klass=nil, @plural_name="resources", @type=nil, @foreign_type=nil, @constructable=true, @association_scope_cache=#<Concurrent::Map:0x00007f8fe5593680 entries=0 default_proc=nil>, @foreign_key="resource_id">

There is probably no easy way how to obtain scope of associated model ... :-(

@excid3
Copy link
Collaborator

excid3 commented Nov 17, 2020

Are you able to provide a test case that replicates this?

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

No branches or pull requests

2 participants