-
Notifications
You must be signed in to change notification settings - Fork 2
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
[WIP] When a record is deleted it should use unscoped association calls #4
base: main
Are you sure you want to change the base?
Conversation
Hmm I just saw #3 I think my approach still works with Rails4?? |
next unless association.klass.include?(Restorable) | ||
associate_method(association) | ||
end | ||
Restorable.associated_classes << self.class |
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 is updating global state :-/ I'm not quite sure what this is supposed to do – do you want to track which AR classes include Restorable? If so, there are simpler ways of doing it.
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.
I had trouble tapping into the a time after AR defined the association methods. My solution was to do it in an after_initialize
callback because I knew AR wouldn't redefine them again at that point. And because I don't want to redefine the association methods after each initialization, I kept track of the classes where I redefined the.
Does that make sense?
@vkmita can you rebase this on master? |
edef496
to
5f4800f
Compare
@libo @dasch @bquorning @pdeuter
I think this addition is useful, for example, you can retrieve a deleted category, and gracefully get the default_translation without having to do something like this:
Instead we can simply do:
The thing I'm having trouble with is the timing of redefining the association methods. If I do a class_eval at the time the module is included it doesn't work because it seems like Rails is redefining the has_many associations after I initially redefine them. The only solution I came up with for that was overriding the methods in an after_initialize callback, and simply marking which classes were overridden so we don't do it twice.
What do you guys think?