-
Notifications
You must be signed in to change notification settings - Fork 129
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
NoMethodError: undefined method `where' for HistoryTracker:Class #169
Comments
I released 0.6.0 an hour ago, can you please try that? |
@dblock I created sample app using ruby 2.3.0, rails 5.0.0, mongoid(github master branch) and mongoid(0.6.0).
2.3.0 :014 > user = User.create(email: '[email protected]', password: 'prasad123', password_confirmation: 'prasad123')
=> #<User _id: BSON::ObjectId('57d8e68b5f10de200053b8f6'), created_at: nil, email: "[email protected]", modifier_id: nil, name: nil, points: 0, updated_at: nil, version: nil>
2.3.0 :015 > user.valid?
=> false
2.3.0 :016 > user.errors
=> #<ActiveModel::Errors:0x007f9af9def670 @base=#<User _id: BSON::ObjectId('57d8e68b5f10de200053b8f6'), created_at: nil, email: "[email protected]", modifier_id: nil, name: nil, points: 0, updated_at: nil, version: nil>, @messages={:modifier=>["can't be blank"]}, @details={:modifier=>[{:error=>:blank}]}> Also, I tried using the latest version(0.6.0) for an existing open-source project and it results in the same error( NoMethodError: undefined method `where' for HistoryTracker:Class). This |
@dblock This issue has been raised because of |
I would try to turn it into a failing spec here next. |
@dblock @sivagollapalli that might be the case but the app link that I have provided in the latest comment runs on rails 4.2. |
for further explanation, 2.3.0 :003 > HistoryTracker.ancestors
=> [HistoryTracker, Mongoid::History::Trackable, Object, PP::ObjectMixin, EasyDiff::SafeDup, ActiveSupport::Dependencies::Loadable, Mongoid::Extensions::Object, BSON::Object, Origin::Extensions::Object, JSON::Ext::Generator::GeneratorMethods::Object, Kernel, BasicObject] expect for Mongoid::History::Trackable and Mongoid::Extensions::Object no other Mongoid classes/modules are present in the chain which seems weird. |
Not entirely sure if this is related, but I'll just throw it out there. I've had an issue with Rails 5.0.1, Mongoid 6.0.2 and Mongoid-History 0.6.0. The app acts as a standalone API and shares its database with a Rails 4 app. record.errors.messages
#=> :modifier=>["can't be blank"] So, after a little research (with a short stop in this thread) I ended up reading the mongoid config specs and realised they are setting Simply adding an initializer solved the problem: # config/initializers/mongoid_belongs_to_required_by_default.rb
Mongoid.belongs_to_required_by_default = false |
It sounds like a separate (and real) problem @Ninigi. |
@dblock so, should I open an issue? The problem is an unexpected behaviour because of the Mongoid default setting, a simple comment about it in the README would already fix it (since you only need to add the initializer) |
I think you should and maybe try to write a spec for it? At the very least it's a bug, and your solution is a workaround, but we should actually fix the underlying issue. |
Ok, will do. I think the solution is going to be easy enough, so probably will have a PR attached. Thanks for your time :) |
@Ninigi you just saved my butt on a project, thanks for that. |
@DarthHater thanks for the PR, I wanted to do it and never found the time... And then I forgot >.< |
What do we do with this issue here? Looks like |
@dblock The issue basically is that ActiveRecord changed its policy towards relations with Rails 5. Before, when you defined a belongs_to relation, the foreign key was not required (could be null or not), now it is required by default unless stated otherwise. Mongoid adopted that behavior, which breaks mongoid-history if you try to save a history without setting the modifier_id (belongs_to relation), because modifier_id will now be validated for presence by default - hence the It is not related to the original issue I think, but rather to the issue that prasadsurase ran into when creating a sample app:
|
Okay, so I think what we need is either or both documentation that explains this in README and much better error messaging. Care to contribute @Ninigi? |
Would love to help, though kind of new to open source. I'm facing the same issue - switching When I don't turn it off, I simply get an Can't establish if I should set the modifier manually (doesn't seem like the correct approach), or how to debug this and have mongoid history set the modifier to the Additionally, I'm running rails 5.0.2, mongoid 6.1.0, mongoid-history 0.6.1, devise 4.2.1 (also running cancancan)... Thanks! |
I have a solution to my question. Posting it for feedback, or in case anyone else has the problem ... In #139 @dblock mentions that you need to set the modifier explicitly. Seeing as though there is one model at the moment that I want to track changes in, I've added a merge to the strong params method which now looks like this:
This works, so I'll keep it like this for now, unless anyone has a better implementation idea |
Issue for me was that creating through console the modifier_id needs to be passed manually or as some id from seed or as default value like, example:
|
thanks for that @Ninigi |
I am using mongoid-history(0.5.0) with an rails(5.0.0) and mongoid(github master branch). The changes are
When I run 'user.history_tracks' in rails console, I get
Am I missing something or is this a valid bug?
The text was updated successfully, but these errors were encountered: