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

Explicit Association Autosave #127

Merged
merged 4 commits into from Oct 4, 2020
Merged

Explicit Association Autosave #127

merged 4 commits into from Oct 4, 2020

Conversation

Fs02
Copy link
Member

@Fs02 Fs02 commented Oct 3, 2020

!!! This is a breaking changes.

  • Previously, any insert or update will automatically save it's association if not empty, this changes will disable that feature by default, and if needed, it can be enabled by setting struct tag autosave:"true".
    type User struct {
      ID        int
      Name      string
      CreatedAt time.Time
      UpdatedAt time.Time
    
      // autosave disabled by default, it's not make sense to update transaction when updating user
      Transactions []Transaction
    
      // enable autosave, might make sense when the association is tightly coupled.
      Address Address `autosave:"true"`
    }
  • Autosave will still work with Cascade(true). If cascade enabled, it won't go deeper than autosave, and if cascade disabled, all autosave will be ignored.
  • Autosave also applies to Delete operation.
  • Not all association support autosave (for example: many to many Support association using join table such as Many to Many #104), and this explicitness allow REL to validate the use of autosave and tell the user explicitly if autosave is not supported in selected association mode.

@codecov
Copy link

codecov bot commented Oct 3, 2020

Codecov Report

Merging #127 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #127   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           54        54           
  Lines         3630      3641   +11     
=========================================
+ Hits          3630      3641   +11     
Impacted Files Coverage Δ
map.go 100.00% <ø> (ø)
association.go 100.00% <100.00%> (ø)
repository.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 70d8118...637b5ac. Read the comment docs.

@Fs02 Fs02 merged commit 7e4b492 into master Oct 4, 2020
@Fs02 Fs02 deleted the explicit-association-autosave branch October 4, 2020 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant