-
Notifications
You must be signed in to change notification settings - Fork 148
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
Use destroy over delete when deleting translation records #61
Conversation
@mpataki are there any specific reasons why we need to use |
For the sake of possible callbacks in Translation model I guess. Not the worst idea imho, even if it might impact performance as models are fetched, instantiated and deleted one by one... |
Oof, sorry for the ulta-late reply on this. I'm just working out better github notification so things like this don't get lost in the noise. Using As for the performance concern, I leave that to you guys. I know that in my use cases it never had any impact as we aren't really storing new translations on the fly, just from our internal admin panel as people add / update language, but I can't really speak for all users. Thanks for having a look! I'll be sure to be more responsive here in the future. |
@mpataki Thanks for explanation. |
That sounds reasonable. I'll put something together. Thanks! |
You can add some simple configuration code here: I18n::ActiveRecord.configure do |config|
config.cleanup_with_destroy = true
end |
c8c468a
to
4f1a39c
Compare
Ok, this should do it. I ended up adding the configuration to One thing - I've defaulted the configuration to using Let me know if there's anything further you'd like to see changed! |
end | ||
|
||
def self.config | ||
@@config ||= Configuration.new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use @config
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This being a class variable, I don't think that's allowed by ruby. I get this:
NameError: `@config' is not allowed as a class variable name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go with @_config
then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, same thing. Investigating a little further, it's class_variable_set
that's throwing it, and otherwise it's allowed to be @config
(one @
instead of two). I was aiming to avoid exposing a writer for the config on ActiveRecord
, but exposing one and using it over class_variable_set
in the tests accomplishes what you're asking for, if you don't mind the setter being there.
I'll make that change and push so you can see it.
@mpataki PR looks nice, i added one notice. |
1ba21e4
to
dfb53f8
Compare
autoload :Configuration, 'i18n/backend/active_record/configuration' | ||
|
||
class << self | ||
def configure(&block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to pass &block
here, since we using yield
and block_given?
…ing ActiveRecord Translation records no need to pass block here remove setter, use instance_variable_set
3f66cd6
to
54b8c58
Compare
Cool, great work @mpataki, now we have configuration api. |
Ensures that rails callbacks get called on destroy.