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

2.7.3 Inheritance and specify table_name_prefix does not work ( Ruby on rails ) #562

Closed
YumaInaura opened this issue May 10, 2018 · 5 comments

Comments

@YumaInaura
Copy link

When super_users table exists in sqlite

class Super < ApplicationRecord
  # does not work
  self.table_name_prefix = 'super_'

  # work
  # self.table_name = 'super_users'
end

class User < Super
  # does not work
  # self.table_name_prefix = 'super_'

  # work
  # self.table_name = 'super_users'
end

# class User < ApplicationRecord
  # work
  # self.table_name_prefix = 'super_'
# end

command

$ bundle exec annotate app/models/user.rb
Model files unchanged.

Version

  • annotate (2.7.3)
  • rails (5.2.0)
  • ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin16]
@ctran
Copy link
Owner

ctran commented Jun 13, 2018

Could you clarify what "does not work" mean?

@abepark01
Copy link

abepark01 commented Sep 1, 2018

Hello!
I ran into this issue myself using a namespaced model in a standard Ruby on Rails 5.2 application.
What the OP is saying that the table_name is not including the table_name_prefix .

In the example above, the expected table_name is super_users but users is being returned instead.
If you do rails g model super/user it should output the following files...

The problem is that the method table_name does not include the prefix super_.

Again, this may be an issue stemming from rails/rails#21476

app/models/super.rb

class Super < ApplicationRecord
  self.table_name_prefix = 'super_'
end

app/models/super/user.rb

module
  class User < ApplicationRecord
  end
end

@ctran
Copy link
Owner

ctran commented Feb 14, 2019

PR is welcome.

@ctran ctran closed this as completed Feb 14, 2019
@lazyb0ne
Copy link

another way to fix it:
In base model:
def self.table_name
self.prefix_str + self.class_name.underscore.pluralize
end
and it works :)

@hut8
Copy link

hut8 commented Jul 25, 2023

With even the latest version, I'm having trouble getting annotate to annotate some models. It's very strange, because it annotates almost all of the models in my project fine, but it skips a few.

Unable to annotate app/models/metabase_dashboard.rb: Mysql2::Error: Table 'dbname.metabase_dashboards' doesn't exist
Unable to annotate app/models/metabase_dashboard.rb: no implicit conversion of nil into Array
Unable to annotate app/models/project_need.rb: Mysql2::Error: Table 'dbname.project_needs' doesn't exist
Unable to annotate app/models/project_need.rb: no implicit conversion of nil into Array

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

5 participants