-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
[7.x] Refactor the HasMany fieldtype #556
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Previously, it only accepted arrays of `Model` objects (except for when it was being called on a non-runway route, like an entry save).
Released as part of v7.6.0. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request refactors how the Has Many fieldtype handles the saving of relationship updates, to allow for proper support of Has Many fields when using revisions.
When I was digging into #550, I realised that the HasMany fieldtype was pretty broken when used alongside Revisions. Related models were disappearing when trying to save a revision, publishing a revision would throw an error, etc.
This was happening due to how the Has Many fieldtype has worked until now. When you save a model, it'll run the values through the relevant fieldtype
process
methods.In the case of the Has Many fieldtype, the
process
method was where it updated the model's relationships. This has worked fine until we implemented revisions, where you don't want it those relationships to be actually updated until you "publish" the revision.To address these issues, I had to do quite a bit of refactoring around how & when relationship updates happen. Here's a few notes on the implementation, for those interested:
Relationships
class to saving relationship updates.Relationships::save
method then gets called right after the model is saved (or the revision is published).HasManyFieldtype::process
method in favour of the newRelationships
stuff.runwayRelationships
property to the model to handle this. It's just a simple array with IDs in it.PreparesModels
(before other fields get set as "attributes" on the model). They're then included in the revision's attribute data when it gets saved.HasRunwayResource::makeFromRevision
), it sets the property again, which is then accessed when publishing a revision inHasRunwayResource::publish