Skip to content

Attempt to cache inverse of has_many#292

Open
kindrowboat wants to merge 1 commit intoremi:masterfrom
kindrowboat:td-cache_inverse_of_has_many
Open

Attempt to cache inverse of has_many#292
kindrowboat wants to merge 1 commit intoremi:masterfrom
kindrowboat:td-cache_inverse_of_has_many

Conversation

@kindrowboat
Copy link
Copy Markdown
Contributor

Previous behavior was to set the inverse of has_many objects as attributes.
This can be problematic in the case of attempting to serialize attributes
(think, infinite recursion). It is also different than how most other
relationship are expected to behave (i.e. saving them in the
Association@cached_data. This commit exposes Association#cached_data and
has the HasManyAssociation#fetch attempt to save the inverse relationship in
the cached_data if such a relationship/association is defined (most often
through the AssociationProxy.

Previous behavior was to set the inverse of `has_many` objects as attributes.
This can be problematic in the case of attempting to serialize attributes
(think, infinite recursion).  It is also different than how most other
relationship are expected to behave (i.e. saving them in the
`Association@cached_data`.  This commit exposes `Association#cached_data` and
has the `HasManyAssociation#fetch` attempt to save the inverse relationship in
the `cached_data` if such a relationship/association is defined (most often
through the `AssociationProxy`.
voltechs added a commit to TwilightCoders/her that referenced this pull request Mar 31, 2026
Ref: remi#292

When fetching has_many associations, set the inverse parent through
the association's cached_result rather than injecting it directly
into the child's attributes hash. This prevents the parent object
from appearing as a serializable attribute on child records.
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