Skip to content

Proper reversal of relations in sub queries - #171

Draft
nilmerg wants to merge 4 commits into
mainfrom
fix/proper-reversal-of-relations-in-sub-queries-170
Draft

Proper reversal of relations in sub queries#171
nilmerg wants to merge 4 commits into
mainfrom
fix/proper-reversal-of-relations-in-sub-queries-170

Conversation

@nilmerg

@nilmerg nilmerg commented Aug 20, 2026

Copy link
Copy Markdown
Member

Changes the way relations can be reversed drastically as it is now possible to influence the relation to use during reversal with ::setReverseName(string) which allows Icinga DB Web to drop the error-prone to.from and from.to relations.

An additional change is that it is now not mandatory anymore to define relations that are solely being required because of sub-queries. Missing relations on the reversed path are automatically registered. For this, each relation type now has its specific counterpart which is possible to override with ::setReverseClass(class-string). The default however, is to use the same type which is the case for BelongsToOne and BelongsToMany. For BelongsTo a sane override has been chosen that is based on how it's used at the moment in our products, as HasOne and HasMany may both be appropriate. But the latter clearly is used more often.

Since ::reverse() uses the source's table alias by default as reverse name, a deprecation notice is triggered if the original forward path uses a different name, indicating that it is necessary to use this name as explicit reverse name.

fixes #170

This is required to establish type symmetry as the base's
methods also accept `NULL` to be able to direcly pass a
getters return value to the appropriate setter.
Relations know it better how to and the override of
`resolveFilter` in `BelongsToMany` proves it as it
turned out that it is necessary to allow referencing
the junction table in either the filter or the through
filter in order to be able to better reverse relations.
Changes the way relations can be reversed drastically
as it is now possible to influence the relation to use
during reversal with `::setReverseName(string)` which
allows Icinga DB Web to drop the error-prone `to.from`
and `from.to` relations. An additional change is that
it is now not mandatory anymore to define relations
that are solely being required because of sub-queries.
Missing relations on the reversed path are automatically
registered. For this, each relation type now has its
specific counterpart which is possible to override
with `::setReverseClass(class-string)`. The default
however, is to use the same type which is the case
for `BelongsToOne` and `BelongsToMany`. For `BelongsTo`
a sane override has been chosen that is based on how
it's used at the moment in our products, as `HasOne`
and `HasMany` may both be appropriate. But the latter
clearly is used more often.
Since `::reverse()` uses the source's table alias by default
as reverse name, a deprecation notice is triggered if the
original forward path uses a different name, indicating that
it is necessary to use this name as explicit reverse name.

fixes #170
@nilmerg nilmerg added this to the v1.0.0 milestone Aug 20, 2026
@nilmerg nilmerg self-assigned this Aug 20, 2026
@cla-bot cla-bot Bot added the cla/signed label Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query::createSubQuery() attemtps to call BelongsTo::getThroughFilter()

1 participant