Skip to content

$relatedQuery shouldn't mutate loaded relations #599

@drew-r

Description

@drew-r

I find that $relatedQuery.findById and $relatedQuery.insert will mutate the relations loaded on a model instance.
I find that this isn't particularly useful & tends to create more problems than it avoids.

Consider e.g

  • Loading a model with a filtered relation. Any insert or find operation on the same relation using $relatedQuery breaks the filter.
  • A 'shortcut' relation that is defined only for syntactic sugar (e.g often this is the inverse of a more common access pattern - e.g find genre related to this artist, where you usually access genre->artist & don't really want genre nested under artist when serialized etc.) - querying with $relatedQuery you now have an unwanted piece of data non-obviously nested in your model

My proposal would be to disable this behaviour as I don't think a complete solution exists here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions