Skip to content
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-4528 Add more dirty methods #5440

Merged
merged 5 commits into from
Aug 25, 2022

Conversation

comandeo
Copy link
Contributor

@comandeo comandeo commented Aug 10, 2022

@comandeo comandeo changed the title RUBY-4528 Add more dirty methods MONGOID-4528 Add more dirty methods Aug 10, 2022
#
# @return [ true | false ] Whether the attribute change the next time we save.
def will_save_change_to_attribute?(attr, **kwargs)
attribute_changed?(attr, **kwargs)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is safe to make will_save_change_to_attribute? basically an alias to attribute_changed?.
See rails/rails#32694 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah agreed.

@comandeo comandeo marked this pull request as ready for review August 11, 2022 07:22
person.name = 'Jane'
person.save
# "will_save_change_to_attribute?(:name): true"
# attribute_was(:name): Jane => New value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does attribute_was not look back before the last save? if not, can you mention that here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

#
# @return [ Array<Object> | nil ] If the attribute was changed, returns
# an array containing the original value and the saved value, otherwise nil.
def saved_change_to_attribute(attr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also add the saved_change_to_attribute? method. I feel like that should be rather trivial to implement at this point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

#
# @return [ true | false ] Whether the attribute change the next time we save.
def will_save_change_to_attribute?(attr, **kwargs)
attribute_changed?(attr, **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah agreed.

end

def saved_change_to_attribute_values_before
@saved_change_to_attribute_values_before ||= Hash.new([])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this copies the same array object into all new hash values which is generally not desirable. Unless this is specifically desired this should use the new with block syntax.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

comandeo-mongo and others added 4 commits August 18, 2022 15:38
Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>
Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>
Copy link
Contributor

@p-mongo p-mongo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I skimmed this but I don't see anything to object to.

@comandeo comandeo merged commit bb1dedf into mongodb:master Aug 25, 2022
@comandeo comandeo deleted the 4528-add-more-dirty-methods branch August 25, 2022 09:54
comandeo pushed a commit that referenced this pull request Aug 29, 2022
Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>
jamis added a commit that referenced this pull request Mar 14, 2023
…) to master (#5561)

* MONGOID-5334 ensure localized demongoization works with symbol keys (#5416)

* MONGOID-5334 ensure localized demongoization works with symbol keys

* MONGOID-5334 add type check

* MONGOID-5334 change back type check

* MONGOID-5437 extract fallback enabling logic into macro (#5428)

* MONGOID-5438 initial changes from Johnny's PR

* MONGOID-5438 additional changes from johnny's
PR

* MONGOID-5437 fix tests

* MONGOID-5437 fix uniqueness test

* MONGOID-5334 enforce Hash type in localized demongoize (#5430)

* MONGOID-5334 add type check

* MONGOID-5334 change back type check

* MONGOID-5334 enforce Hash type in localized demongoize

* MONGOID-5456 cast castable values for integer/float/big decimal (#5431)

* MONGOID-5456 cast castable values for integer/float/big decimal

* MONGOID-5456 assert duration

* MONGOID-4403 Support Dirty Tracking changed from/to (#5432)

* MONGOID-4403 Support Dirty Tracking changed from/to

* Apply suggestions from code review

Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>

* MONGOID-4403 add false example

Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>

* MONGOID-5456 Add documentation for responding to to_* (#5434)

* MONGOID-5456 Add documentation for responding to to_*

* Apply suggestions from code review

Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>

Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>

* MONGOID-5461 Change custom field options example (#5438)

* MONGOID-5461 Change custom field options example

* Apply suggestions from code review

Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>

Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>

* MONGOID-5458 Document fallbacks option on localized fields (#5439)

* MONGOID-5460 Update custom field type protocol documentation (#5441)

* MONGOID-5457 Document + example of non-String field types in localized fields (#5444)

* MONGOID-4698 update warning when overriding criteria methods in scope (#5442)

* MONGOID-4698 update warning when overriding criteria methods in scope

* Apply suggestions from code review

Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>

Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>

* MONGOID-5417 Fix memory leak when call 'with' (#5409)

* MONGOID-4528 Add more dirty methods (#5440)

Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>

* MONGOID-4698 Correct warning to point out that klass.band doesnt conflict (#5450)

* MONGOID-5226 Allow setting "store_in collection" on document subclass (#5449)

* MONGOID-5226 Allow setting "store_in collection" on document subclass

* remove comment

* MONGOID-5226 add docs and testing

* Apply suggestions from code review

Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>

* MONGOID-5226 answer comments

Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>

* MONGOID-5293 put legacy_attributes in 7.5 defaults (#5425)

* MONGOID-5293 put legacy_attributes in 7.5

* switch order

* MONGOID-5293 fix defaults tests

* MONGOID-5438 Implement local override for i18n parameters (#5427)

* MONGOID-5438 Implement local override for i18n parameters

* MONGOID-5438 get rid of enfore_available_locale changes

* MONGOID-5438 get rid of before alls

* MONGOID-5438 fix tests caused by rspec precedence

* MONGOID-5438 attempt to fix tests when fallbacks disabled

* MONGOID-5438 make fallbacks default to return [self]

* MONGOID-5438 reset fallbacks

* MONGOID-5438 attempt to fix tests

* MONGOID-5438 retry_test

* MONGOID-5438 undefine fallback methods after fallback tests

* MONGOID-5438 add back defaults

* MONGOID-5438 use new macros

* MONGOID-5438 use before and after suite

* MONGOID-5438 update mrss

* MONGOID-5438 remove suite checks

* MONGOID-5370 Add collection options support (#5452)

Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>

* MONGOID-5474 add readonly! and raise on save/update (#5455)

* MONGOID-5474 add readonly! and raise on save/update

* MONGOID-5474 flip flag for 9.0 and add default

* MONGOID-5474 fix error tests

* Update spec/mongoid/config_spec.rb

* Apply suggestions from code review

Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>

* Update lib/mongoid/config.rb

Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>

Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>

* MONGOID-5474/MONGOID-5478 add docs and release notes (#5457)

* MONGOID-5474 add docs and release notes

* MONGOID-5474 use read-only

* MONGOID-5474 add configuration docs

* MOGOID-5474 switch order of flag docs

* add MONGOID-5477 use case

* MONGOID-5477 / MONGOID-5474 / MONGOID-5478 add user test (#5459)

* MONGOID-5474 add user test

* MONGOID-5474 change to read-only

* MOGOID-5474 switch order of flag docs

* MONGOID-5476 update 8.1 installation version (#5464)

* MONGOID-5474 flip the feature flag in 8.1 (#5456)

* MONGOID-5474 flip the feature flag in 8.1

* MONGOID-5474 flip flag in configuration

* MONGOID-5474 update config test

* MONGOID-5227 Add test and adjust docs for dotted attribute assignment in default scope (#5474)

* MONGOID-5227 Add test and adjust docs for dotted attribute assignment in default scope

* MONGOID-5227 adjust docs

* MONGOID-5227 clarify the docs and add tests

* Update docs/reference/queries.txt

Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>

Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>

* MONGOID-5493: Update Gem::Specification team info (#5476)

* MONGOID-5312 Document attributes method in reference (#5477)

* MONGOID-5312 Document attributes method in reference

* Apply suggestions from code review

Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>

* MONGOID-5312 update languagw

Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>

* MONGOID-5082 Create contributing guidelines (#5472)

* MONGOID-5082 Create contributing guidelines

* MONGOID-5082 propose test coverage

* MONGOID-5082 whitespace

* MONGOID-5082 update language

* add intro

* MONGOID-5445 Add load_async to criteria (#5454)

Co-authored-by: Neil Shweky <neilshweky@gmail.com>
Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>

* MONGOID-5291 Clarify whether :touch option is applicable for all updates (#5481)

* MONGOID-5261 Use config_override when a test requires a certain configuration option value (#5479)

* MONGOID-5261 Use config_override when a test requires a certain configuration option value

* fix syntax error

* MONGOID-5261 a little more cleanup

* MONGOID-5261 more cleanup

* more clean up

* MONGOID-5261 add persistence context override

* MONGOID-5261 add comment

* MONGOID-5100 allow selector arguments for .exists? (#5466)

* MONGOID-5100 allow selector arguments for .exists?

* MONGOID-5100 add examples to the docstrings

* MONGOID-5100 add docs and release notes

* Empty-Commit

* MONGOID-5100 allow false to be passed

* MONGOID-5100 update docs and docstrings

* MONGOID-5100 remove false as a param

* MONGOID-5100 put back nil/false

* MONGOID-5100 fix memory tests and fix limit == 0

* MONGOID-5262 Implement local time zone override for tests (#5480)

* MONGOID-5506 Update 8.x docs to document unscoped behavior changing in 9.0 (#5483)

* MONGOID-5506 Update 8.x docs to document unscoped behavior changing in 9.0

* Update lib/mongoid/scopable.rb

* RUBY-2942: Update documentation links (#5482)

* MONGOID-5363 Change #upsert to perform updating upsert rather than replacing upsert (#5492)

* MONGOID-5363 add :replace option to upsert method

* MONGOID-5363 add docs, release notes for 8.1/9.0

* MONGOID-5363 switch default in 8.1 (#5493)

* MONGOID-5363 update docstrings, flag default, and tests for 8.1

* specify default in mongoid 9

* MONGOID-5331 Document hash assignment to associations (#5494)

* MONGOID-5331 change buildable docs

* MONGOID-5331 add proxy tests and fix embedded_in proxy

* MONGOID-5331 update models

* Update spec/mongoid/association/embedded/embedded_in/proxy_spec.rb

* MONGOID-5331 update doc strings in batchable

* MONGOID-5331 add docs

* MONGOID-5331 add docs/release notes

* Apply suggestions from code review

* Update spec/mongoid/association/embedded/embedded_in/proxy_spec.rb

* RUBY-3097 add/use monotonic time for deadlines (#5491)

* RUBY-3097 add/use monotonic time for deadlines

* remove license and fix tests

* MONGOID-3834 Document association availability in custom getters and setters (#5503)

* MONGOID-3834 Document association availability in custom getters and setters

* add callbacks note

* MONGOID-5496: Update Getting Started (Rails) tutorial for Rails 7 (#5509)

* Clone Rails Tutorial and create variation for Rails 7

* Update Existing Application docs for Rails 7

* MONGOID-5532: Fix path to comments partial (#5511)

* MONGOID-5533: Unnecessary edits to Comment model in Rails Getting Started (#5512)

* Add note about workaround for MONGOID-4885 in Rails 6 docs

* Fix whitespace

* MONGOID-5521 migrate Mongoid docs to snooty (#5513)

* fix code blocks

* MONGOID-5521 fix all parse errors

* build docs with github action

* Revert "build docs with github action"

This reverts commit 9ffda44.

* MONGOID-5496: Update Rails 7 Tutorial (#5515)

* Remove `--skip-bundle` from _Optionally Skip Tests_ section

* MONGOID-5518: Add Puma dependency to Sinatra tutorial (#5516)

* MONGOID-5453 Add .none_of query method (#5524)

* "none_of" query method

* update docs and release notes

* fix underline for header

* MONGOID-5539: Fix example in aggregation reference documentation (#5536)

* Update aggregation.txt

* Update aggregation.txt

* MONGOID-5228 disallow _id to be updated on persisted documents (ported to 8.1-stable) (#5545)

* port #5542 to 8.1-stable

* test tweak

* update 8.1 release notes to mention immutable_ids

* MONGOID-5490: Deprecate :use_activesupport_time_zone (#5488)

* Deprecate the use_activesupport_time_zone_deprecated config option.

* Typo

* Update config.rb

* Update mongoid-8.1.txt

---------

Co-authored-by: shields <shields@tablecheck.com>

* MONGOID-5509: Deprecate all feature flags which were introduced in Mongoid 7.x (#5489)

* Deprecate the use_activesupport_time_zone_deprecated config option.

* Typo

* Mongoid 8.1 should deprecate all feature flags which were introduced in the 7.x series, with intent to remove them in Mongoid 9.0.

---------

Co-authored-by: shields <shields@tablecheck.com>

* Remove :use_activesupport_time_zone option + improve readme around timezone usage given the change

* Remove deprecated :broken_aggregables config option

* Remove deprecated :broken_alias_handling config option

* Remove deprecated :broken_and config option

* Remove deprecated :broken_scoping config option

* Remove deprecated :broken_updates config option

* Remove deprecated :compare_time_by_ms config option

* Remove deprecated :legacy_attributes config option

* Remove deprecated :legacy_pluck_distinct config option

* Remove deprecated :legacy_triple_equals config option

* Remove deprecated :object_id_as_json_oid config option

* Remove deprecated :overwrite_chained_operators config option

* Drop support for config.load_defaults versions "7.3", "7.4", "7.5", as their options are no longer available.

* Fix broken spec in Mongoid 8.1

---------

Co-authored-by: Neil Shweky <neilshweky@gmail.com>
Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>
Co-authored-by: Dmitry Rybakov <dmitry.rybakov@mongodb.com>
Co-authored-by: Alex Bevilacqua <alex@alexbevi.com>
Co-authored-by: Jamis Buck <jamisbuck@gmail.com>
Co-authored-by: Jamis Buck <jamis.buck@mongodb.com>
Co-authored-by: shields <shields@tablecheck.com>
carlosantoniodasilva added a commit to heartcombo/devise that referenced this pull request Mar 31, 2023
It appears Mongoid 8.0+ slightly [changed dirty tracking] behavior to
more closely match Active Model/Record, however they haven't yet
introduced the [new methods] that match the latest API, that seems to be
coming on Mongoid 8.1 only.

The changes here try to accommodate for that by determining which
"attribute_changed?" method to call depending on whether the
"*_previously_*" version exists. Newer versions of AR (5.1+) will
continue to use the new API / methods, whereas previous versions and
Mongoid 8.0+ will use these tweaked versions. No behavior should change
for AR, but it will hopefully support Mongoid 8.0+ now.

[changed dirty tracking]
mongodb/mongoid#5092

[new methods]
mongodb/mongoid#5440
carlosantoniodasilva added a commit to heartcombo/devise that referenced this pull request Oct 13, 2023
It appears Mongoid 8.0+ slightly [changed dirty tracking] behavior to
more closely match Active Model/Record, however they haven't yet
introduced the [new methods] that match the latest API, that seems to be
coming on Mongoid 8.1 only.

The changes here try to accommodate for that by determining which
"attribute_changed?" method to call depending on whether the
"*_previously_*" version exists. Newer versions of AR (5.1+) will
continue to use the new API / methods, whereas previous versions and
Mongoid 8.0+ will use these tweaked versions. No behavior should change
for AR, but it will hopefully support Mongoid 8.0+ now.

[changed dirty tracking]
mongodb/mongoid#5092

[new methods]
mongodb/mongoid#5440
carlosantoniodasilva added a commit to heartcombo/devise that referenced this pull request Apr 9, 2024
It appears Mongoid 8.0+ slightly [changed dirty tracking] behavior to
more closely match Active Model/Record, however they haven't yet
introduced the [new methods] that match the latest API, that seems to be
coming on Mongoid 8.1 only.

The changes here try to accommodate for that by determining which
"attribute_changed?" method to call depending on whether the
"*_previously_*" version exists. Newer versions of AR (5.1+) will
continue to use the new API / methods, whereas previous versions and
Mongoid 8.0+ will use these tweaked versions. No behavior should change
for AR, but it will hopefully support Mongoid 8.0+ now.

[changed dirty tracking]
mongodb/mongoid#5092

[new methods]
mongodb/mongoid#5440
carlosantoniodasilva added a commit to heartcombo/devise that referenced this pull request Apr 10, 2024
It appears Mongoid 8.0+ slightly [changed dirty tracking] behavior to
more closely match Active Model/Record, however they haven't yet
introduced the [new methods] that match the latest API, that seems to be
coming on Mongoid 8.1 only.

The changes here try to accommodate for that by determining which
"attribute_changed?" method to call depending on whether the
"*_previously_*" version exists. Newer versions of AR (5.1+) will
continue to use the new API / methods, whereas previous versions and
Mongoid 8.0+ will use these tweaked versions. No behavior should change
for AR, but it will hopefully support Mongoid 8.0+ now.

[changed dirty tracking]
mongodb/mongoid#5092

[new methods]
mongodb/mongoid#5440
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants