-
Notifications
You must be signed in to change notification settings - Fork 88
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
Add skip_timestamps
option
#486
Add skip_timestamps
option
#486
Conversation
5a545eb
to
1ad352b
Compare
Huh. I have wanted #update with skip_timestamps but never #create. Typically I want that because I want to "soft touch" some record without altering the breadcrumb trail for some reason...which I can't think of why I'd want to do that on a create. I think the timestamp columns are specified as NOT NULL (or at least they are in my databases). Wouldn't that cause a problem? |
35e9eca
to
177c930
Compare
Hmm yeah you're right. I hadn't considered DB level constraints. I've removed it from create and also squashed some of the commits to tidy up the branch. |
@stufro I think that you should keep the option to create records while skipping timestamps if the created_at and updated_at values are already present. That's the current gap, creating records in bulk that already have timestamps that want to be preserved but they aren't at the time of creation. Database constraints will error on their own for the user, so I wouldn't worry about policing that from inside of Granite. I've had instances where we did imports and ignored the existence of the timestamps during creation but allowed them to be updated if/when the record was updated. |
@crimson-knight ah yes I suppose that might also help with resolving #481? I have made the change. |
1f8911b
to
495776c
Compare
495776c
to
c467b4a
Compare
Resolves #318
This adds the ability to pass
skip_timestamps: true
toupdate
andupdate!
methods. To do this I had to change thesave
method to acceptskip_timestamps
so to avoid inconsistent behaviour I have also added the option to thecreate
andcreate!
methods.To achieve this I had to remove the type definition of
args
on the method definition so that either aGranite::ModelArgs
or aNamedTuple
can be passed in withskip_timestamps
, I originally added another method overload for this case as you can see in the first commit e6f917e. Open to thoughts on this.I have also updated the crud.md docs to describe this feature and added a missing example for
save(validate: false)