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

Add columns managed by Globalize gem #602

Merged
merged 2 commits into from
Jan 20, 2020
Merged

Conversation

peterfication
Copy link
Contributor

Globalize hooks into the model and removes the translated columns
from the klass.columns. This commit checks if globalize is
hooked into the model and adds the necessary columns to the
annotation array.

@peterfication
Copy link
Contributor Author

@ctran did you have to chance so far to have a look at it?

@dvdoliveira
Copy link

Hey @ctran any chance that this PR could be reviewed and included in the next release?
I'm also using annotate_models with the globalize gem and noticed the same issue reported by @peterfication here.

@peterfication
Copy link
Contributor Author

@drwl you seem to be actively working on this project. Can you have a look at the idea of this PR? I will rebase or restructure the code but only if there is a chance that it gets merged.

@ctran
Copy link
Owner

ctran commented Dec 18, 2019

Yes, we'll review and merge it.

@peterfication peterfication force-pushed the add-globalize branch 3 times, most recently from f2216b8 to ab4cd2c Compare December 18, 2019 07:39
@peterfication
Copy link
Contributor Author

I rebase and restructured my added code a little bit. I'm still missing tests so this will be the next step. Is it the right approach to mock all methods from the globalize gem that are being used by my code?

@peterfication
Copy link
Contributor Author

And I'm wondering whether this should be added to the Rubocop config:

Metrics/BlockLength:
  Exclude:
    - 'spec/**/*.rb'

wdyt?

@peterfication peterfication force-pushed the add-globalize branch 2 times, most recently from cb9405c to e42a3ac Compare December 19, 2019 16:26
@ctran
Copy link
Owner

ctran commented Dec 19, 2019 via email

Globalize hooks into the model and removes the translated columns
from the `klass.columns`. This commit checks if globalize is
hooked into the model and adds the necessary columns to the
annotation array.
RSpec spec files can contain long blocks easily because
of the outher describe methods. So this rule makes not too much
sense for these files.
@drwl
Copy link
Collaborator

drwl commented Jan 20, 2020

@peterfication thanks for the PR! Gonna merge it in

@bartoszkopinski
Copy link

bartoszkopinski commented Feb 24, 2020

Why is it including the ID column as well? How do I disable globalize annotations? It looks confusing since the columns aren't really there.

@peterfication
Copy link
Contributor Author

(1) Which ID column do you mean? It shouldn't include the one from globalize. If this is the case for your setup, it's a bug. Can you please share the versions you use (Rails, globalize, annotate_models)?

(2) I'm very sorry for not picking a sensible default here. There should have been an option to enable it and the default should have been false. @drwl should I add such an option with the default false?

vfonic pushed a commit to vfonic/annotate_models that referenced this pull request May 8, 2020
* Add columns managed by Globalize gem

Globalize hooks into the model and removes the translated columns
from the `klass.columns`. This commit checks if globalize is
hooked into the model and adds the necessary columns to the
annotation array.

* Disable Rubocop Metrics/BlockLength for spec files

RSpec spec files can contain long blocks easily because
of the outher describe methods. So this rule makes not too much
sense for these files.
@cddso
Copy link

cddso commented Sep 16, 2020

I noticed the same behavior with table names that consist of multiple words (e.g. MyCar). Here a .downcase is used, but this results in mycar instead of my_car.

foreign_column_name = [
        klass.translation_class.to_s
             .gsub('::Translation', '').gsub('::', '_')
             .downcase,
        '_id'
      ].join.to_sym

Globalize uses a different method to determine the foreign key.

t.references table_name.sub(/^#{table_name_prefix}/, '').singularize,

Defined here: https://github.com/globalize/globalize/blob/master/lib/globalize/active_record/migration.rb#L82

Perhaps a solution is to use a similar approach and use the table name of the class instead of the table name of the translation class. Alternative might be to use .underscore over .downcase but this can potentially also result in incorrect names where capital letters are not necessarily a breakpoint (ABChart as model could have a_b_chart or ab_chart as table name)

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.

6 participants