Document why parent_data is required in ActiveRecordCoder#66
Open
navidemad wants to merge 1 commit into
Open
Conversation
`parent_data` in `#generate` looks removable but is load-bearing, and nothing in the code said why. A child replays its parent's rows by calling `parent.mount` inside the generate block, but those INSERTs go through `execute_batch` tagged "FixtureKit Insert", which the sql.active_record subscriber cannot attribute to a model — so the parent's models never enter `captured_models` on their own. `captured_models.merge(parent_data.keys)` puts them back, keeping the child cache self-contained (mountable without the parent's cache file). Add a comment at the merge site in `#generate` and a pointer at the `execute_batch` tag in `#mount` so a future contributor doesn't drop `parent_data` and quietly break inherited fixtures. Comments only; no behavior change.
1 task
This file contains hidden or 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
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.
Summary
parent_datainActiveRecordCoder#generatelooks removable but isn't, and nothing in the code said why. This adds the missing comments so the next person doesn't delete it and quietly break inherited fixtures.Why parent_data is required
A child fixture replays its parent's rows by calling
parent.mountinside thegenerateblock. Those INSERTs run throughexecute_batchunder the log tag"FixtureKit Insert", which thesql.active_recordsubscriber can't attribute to a model. So the parent's models never land incaptured_modelson their own.captured_models.merge(parent_data.keys)puts them back, which is what keeps a child cache self-contained: you can mount it without the parent's cache file on disk.I did look at removing
parent_databy recapturing the parent's models during the replay instead. It isn't a clean win. Per-model tagging would mean de-batching the one-execute_batch-per-connection call thatfixture_cache_spec.rbpins. The other option, stashing replayed models on the coder instance forgenerateto read back, swaps the explicit parameter for hidden state that depends on mount running inside generate's block. Both are worse than what's there, so the comment also records that the parameter is load-bearing.Change
Comments only, in two places: the merge site in
#generateand theexecute_batchtag in#mount. No behavior change. The existing "includes parent fixture model records when saving inherited fixtures" spec already covers the behavior.