-
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
ConnectionNotEstablished when calling has_paper_trail #177
Comments
I was able to work around this with:
I still maintain that it is undesirable to impose a limitation on the model that it cannot be required until a connection has been established, given that ActiveRecord itself has no such limitation. |
@cout - Under what circumstances did you run into this? Were you trying to run a rake task or something? Looks very similar to rubygems/bundler#1946. Looks like the solution may be to update the |
The following snippet is sufficient to trigger the exception:
Although it is the same exception, I'm fairly certain this has nothing to do with the bug you referenced. The i18n-active_record gem is nowhere in the exception pathway. The problem has to do with calling primary_key() when there is no active connection to the database. Setting @primary_key explicitly prevents the exception from getting raised. I see three options:
|
It looks as though ActiveRecord has not made a connection to the database yet in your example, which is causing the error to be thrown. That being said, after reviewing your suggestions, I question whether it's really necessary to sort ascendingly by @airblade - is there an explanation for why the |
@batter I'm almost certain you can drop the secondary sort on the primary key. I think I put it in there originally to split ties between version records created with the same timestamp. But I've had a nagging feeling for a while that it's unnecessary -- solving a problem that doesn't exist. |
@cout - Just out of curiosity, in the scenario where you encountered this, were you attempting to use PaperTrail outside of Rails? I only ask because it seems to me that the has_many relationship is lazily-evaluated, in the sense that the module that defines the As far as I can tell, that gets called after ActiveRecord has instantiated a connection to the database in the rails boot cycle, so it would not be encountered if using PaperTrail in Rails as the documentation outlines. That being said, we are exploring the possibility of supporting usage of PaperTrail outside of Rails, so I still think it's worthy to address this issue. |
Yes, in the case where I'm getting the failure, paper trail is being used On Tue, Oct 30, 2012 at 3:04 PM, Ben Atkins [email protected]:
|
I get a ConnectionNotEstablished error when I call has_paper_trail from my model. The problem seems to be that primary_key() cannot be called before there is a connection. The solution to this is not obvious. Refactoring the call would at least make it possible to monkey-patch paper_trail in my application.
The text was updated successfully, but these errors were encountered: