Skip to content

Document why parent_data is required in ActiveRecordCoder#66

Open
navidemad wants to merge 1 commit into
Gusto:mainfrom
navidemad:document-parent-data-rationale
Open

Document why parent_data is required in ActiveRecordCoder#66
navidemad wants to merge 1 commit into
Gusto:mainfrom
navidemad:document-parent-data-rationale

Conversation

@navidemad
Copy link
Copy Markdown

Summary

parent_data in ActiveRecordCoder#generate looks 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.mount inside the generate block. Those INSERTs run through execute_batch under the log tag "FixtureKit Insert", which the sql.active_record subscriber can't attribute to a model. So the parent's models never land in captured_models on 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_data by 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 that fixture_cache_spec.rb pins. The other option, stashing replayed models on the coder instance for generate to 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 #generate and the execute_batch tag in #mount. No behavior change. The existing "includes parent fixture model records when saving inherited fixtures" spec already covers the behavior.

`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.
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.

1 participant