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

customizable table names #910

Merged
merged 8 commits into from
Aug 13, 2018
Merged

customizable table names #910

merged 8 commits into from
Aug 13, 2018

Conversation

mizukami234
Copy link
Contributor

background & why

I'm working on a Rails project which has own tags table.
In order to implement a new feature in my project, I need a new, independent tagging system, which AATO is suitable for. But I couldn't install it because duplicate table exists. So I forked this gem to make table names customizable.

implementation

you can simply specify in config:

ActsAsTaggableOn.tags_table = 'aato_tags'
ActsAsTaggableOn.taggings_table = 'aato_taggings'

@seuros seuros self-requested a review July 28, 2018 04:27
Copy link
Collaborator

@seuros seuros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the readme and the changelog ?

@mizukami234
Copy link
Contributor Author

@seuros
I updated readme and changelog.
Thank you for reviewing.

@seuros
Copy link
Collaborator

seuros commented Aug 7, 2018

@mizukami234 do you mind squashing the commits ? The first commits are not linked to your account.

@mizukami234
Copy link
Contributor Author

@seuros
The first commits are actually not mine, added by @junmoka . They're not linked to him, but he said he didn't mind that.

@seuros seuros merged commit 6932226 into mbleigh:master Aug 13, 2018
@Adrian2112
Copy link

I'm trying to implement this but I'm having problems with the models not using the correct table.
this is what I have

# config/initializers/act_as_taggable_on.rb
ActsAsTaggableOn.tags_table = 'aato_tags'
ActsAsTaggableOn.taggings_table = 'aato_taggings'

When calling ActsAsTaggableOn.tags_table on the rails console I'm getting the correct table name but when calling ActsAsTaggableOn::Tag.table_name I'm getting :tags

I think the problem is that the models are loaded before the configuration is set.
How and when are you calling the ActsAsTaggableOn.tags_table = 'aato_tags'?

I made this changes and it is now working for me.
https://github.com/Adrian2112/acts-as-taggable-on/pull/1/files

I can make a PR if you think this is the way to fix it

@mrIllo
Copy link

mrIllo commented May 10, 2021

Why hasn't Adrian2112's pull request already been merged into master?
https://github.com/Adrian2112/acts-as-taggable-on/pull/1/files

This would have saved me hours and hours of debugging and digging into Activerecord's name guessing.

Until this is done, you can patch it through an initializer:

# config/initializers/act_as_taggable_on.rb
ActsAsTaggableOn::Configuration.class_eval do
  def tags_table=(tags_table)
    ActsAsTaggableOn::Tag.table_name = tags_table
    @tags_table = tags_table
  end

  def taggings_table=(taggings_table)
    ActsAsTaggableOn::Tagging.table_name = taggings_table
    @taggings_table = taggings_table
  end
end

ActsAsTaggableOn.tags_table = 'aato_tags'
ActsAsTaggableOn.taggings_table = 'aato_taggings'

@seuros
Copy link
Collaborator

seuros commented May 10, 2021

@mrIllo because it on the wrong repo !

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

Successfully merging this pull request may close these issues.

4 participants