-
Notifications
You must be signed in to change notification settings - Fork 899
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
Fix issues with Rails 4.2.x when not using STI for version models #492
Conversation
👍 As it turns out I'm still suffering this issue with non-STI setup, but only when using reloading features ie spring. |
Oh, this is not a Rails version issue btw as my project is still Rails 3.2.x and suffers the same issue exactly. |
Trying to understand why this fixes the issue... @TobiasBales Do you think it was the timing of |
Not really a timing thing. The other option is to just use
instead of an inheritance chain (which is kind of pointless with the VersionConcern anyway) |
So this is only an issue w/ PaperTrail 4.x? I'm guessing the cause is the loading of the version class via a I don't even know how useful it is anymore but it sounds like maybe there should be a config option to allow users to select whether they want to eager load or lazily load the model. Fixing one issue has broken another :frown: @TobiasBales - Won't you still need the |
Anyone have an answer for me? |
It works for me. Rails 4.2, ruby 2.1.2 @batter - Initialiser is not needed at all. Custom version should be something like:
Thanks both for your help and dedication. |
I'm on Rails 4.1.5, Ruby 2.1.0, and this did not work for me, although I don't know why. Instead, I had to define ...
... over every custom versions class. |
@johnnymo87 sorry, but i must ask. have you changed the gemfile according?
I'm not sure if that fix is for rails 4.2 and above, but I think not. |
@ngelx Yes. Just as a sanity-check, I also did But I tried the other thing he mentioned in here ...
... and this worked as well. |
Thanks @TobiasBales, this PR would address the particular problem of the
If whatever we put in the initializer will be lost when we Instead of the initializer, applications that need to reopen I just tried this out with a new rails app and # app/models/abstract_version.rb
class AbstractVersion < ::ActiveRecord::Base
include PaperTrail::VersionConcern
self.abstract_class = true
end
# app/models/banana_version.rb
class BananaVersion < AbstractVersion
self.table_name = :banana_versions
end
# app/models/banana.rb
class Banana < ::ActiveRecord::Base
has_paper_trail class_name: 'BananaVersion'
end
# in console
Loading development environment (Rails 4.2.2)
Banana.create(grams: 125)
=> #<Banana id: 7, grams: 125>
reload!
Reloading...
=> true
Banana.create(grams: 125)
=> #<Banana id: 8, grams: 125> Tobias and Ben, please take a look at my complete experiment and let me know if I've missed anything. If that all sounds good, I recommend that we close this PR and update the documentation, replacing any mention of an initializer with the suggestions above. |
@jaredbeck - Thanks for taking a detailed look at this. I will pull down the repo you created and play with it ASAP when I get chance, and this is great to know because I believe a lot of the issues people are seeing when they are playing around with My question is, what about users that don't want to use a custom version class of their own, but simply want to modify or add to the way that the standard I guess I still don't fully understand when |
@jaredbeck - Exciting news. I was just playing around with your dummy app, trying to figure out a way to get methods and adjustments to Originally I attempted this: # config/initializers/paper_trail.rb
PaperTrail::Rails::Engine.eager_load!
module PaperTrail
class Version < ActiveRecord::Base
def self.foo
'test'
end
end
end
$ rails c
Loading development environment in sandbox (Rails 4.2.2)
> PaperTrail::Version.foo
=> 'test'
> reload!
Reloading...
=> true
> PaperTrail::Version.foo
NoMethodError: undefined method `foo' for #<Class:0x007fb8c6807290>... But then I got it to work by trying this: # config/initializers/paper_trail.rb
module PaperTrail
module VersionConcern
module ClassMethods
def foo
'test'
end
end
end
end
$ rails c
Loading development environment in sandbox (Rails 4.2.2)
> PaperTrail::Version.foo
=> 'test'
> reload!
Reloading...
=> true
> PaperTrail::Version.foo
=> 'test' So perhaps this is the key to allowing users to openly modify their classes. The downside to this is that it impacts every class that includes |
It is one of the |
Yes, I think we should continue to support that in PaperTrail 4.x. I'd like to have a discussion about deprecating
That sounds good,
Yes, that's my understanding as well. I suspect this behavior is controlled by rails'
I believe
I have two concerns:
|
Ben, I don't see a way to set
Have you, Tobias, or anyone else had a chance to try this technique? Please let us know. |
An alternative to #492 [ci skip]
Thanks @TobiasBales for the PR, and everyone who joined the discussion. Tobias, your solution would work for the particular problem of the Please take a minute to check it out and we can continue this discussion there. Thanks! |
An alternative to #492 [ci skip]
Fixes #488, #483