-
Notifications
You must be signed in to change notification settings - Fork 56
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
Why does user_model have to be defined in every model? #22
Comments
Let me look into this and get back to you. The reason for setting |
Actually, looking at Mongoid::Userstamp::ModelConfig I see this line:
The intention here is that if you only have a single user model in your app then you don't need to explicitly specify this. Are you seeing otherwise? |
Thanks for replying so quickly! I'm seeing that unless I add this line " mongoid_userstamp user_model: 'User' " to my model. I constantly receive an undefined method error for created_by and updated_by always return nil. In your repo spec/support/book.rb this test model defines the user_model as 'User', if User is used by default, I'm not seeing why this is needed, but removing it causes 20 tests to fail for the same reasons I mentioned above. |
@Rodney-QAGeek I'm pretty sure what's happening in this case is that |
(At one time the library gave preference to the model name |
I believe in the case of your specs, you're right. Though, still puzzled why it's not working for projects with only one User class. Given the below example... class User class Account Account will not have created_by or updated_by methods unless I add the line mongoid_userstamp user_model: 'User' |
Try just adding the line |
When I add just that line you mentioned above, I have the created_by and updated_by methods on my Account class, and Mongoid::Userstamp.current_user returns my user. Though when I create an Account, Updated by gets set correctly, but created by does not get set and it also returns the below error on save: NoMethodError: |
Hmm strange. Would you be able to commit some failing test cases with the behavior you'd like to see, I can take a look at it a bit later? |
Reading through the docs on the Readme, it specifies that if your user model is something other than 'User' to define it using: mongoid_userstamp user_model: 'Admin'
However, it appears that even if I used a default 'User' model, I must still specify my mongoid_userstamp user_model: in every model that I want user stamped. I'm confused why this is necessary, It seems like duplication, can you help me understand? You even have it defined as so in your specs.
The text was updated successfully, but these errors were encountered: