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
MONGOID-4741 Include timestamps in generated model by default #4631
MONGOID-4741 Include timestamps in generated model by default #4631
Conversation
ActiveRecord still supports this option. This PR should be rejected in order to be consistent with ActiveRecord |
@johnnyshields
- class_option :timestamps, type: :boolean |
According to https://github.com/rails/rails/blob/master/activerecord/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt the timestamps are not defined by default, but must be requested via the timestamps option. I can see the convenience of having timestamps be added by default, but at the same time the argument can be made for maintaining ActiveRecord compatibility which does not add them by default. @Shigeyuki-fukuda can you reference any sentiment in the Rails community that the timestamps should be added to models by default? |
@p-mongo let's close this. It can be re-opened if ActiveRecord makes a change. |
No I can't. 😓 |
According to README of
Here is the output of README.
@p-mongo I'm not quite sure but I'll try looking into Rails' codebase that passes |
FWIW, as for the consistency with ActiveRecord, setting the default value |
@FumiyaShibusawa let's make this PR match what Rails does. |
It is not immediately clear to me how Rails accomplishes the default of true for timestamps, since that doesn't seem to be set anywhere, but in any event the same behavior in Mongoid can be accomplished, as far as I can tell, by adding |
@Shigeyuki-fukuda If Mongoid's generator is changed to have |
@p-mongo we should copy the Rails options:
|
@p-mongo @johnnyshields |
Does |
This works for me let's merge. |
Thank you for the patch, this will be included in Mongoid 7.1. |
@johnnyshields @p-mongo @saghm |
Summary
The principal changes are as follows.
-timestamp
options from the files generated when userails g model
commandinclude Mongoid::Timestamps
instead of it.