up|self traversal failing to combine results correctly in query for relationship
Author: b-dekuCreated Sep 7, 2026Updated Sep 7, 2026
Labelsbug
Describe the bug
Combining up and self traversal can fail to give the combined results, returning only the entities that would match on self. This reproduction might be an edge case due to there being an additional term with a non-$this source. Querying for just up or self traversal by themselves gives the correct result.
To Reproduce
#include "flecs.h"
#include <iostream>
auto main(int argc, char *argv[]) -> int {
flecs::world ecs;
auto relation = ecs.entity("Relation");
auto root = ecs.entity("Root");
auto child = ecs.entity(root, "Child");
auto sibling = ecs.entity(root, "Sibling");
auto grandchild = ecs.entity(child, "Grandchild");
auto other = ecs.entity("Other").add(relation, root);
std::cout << "Query Up:" << std::endl;
ecs.query_builder()
.with(flecs::ChildOf, "$Source")
.up()
.with(relation, "$Source")
.src("_")
.each([](flecs::entity entity) {
std::cout << entity.name() << std::endl;
});
std::cout << std::endl << "Query Self:" << std::endl;
ecs.query_builder()
.with(flecs::ChildOf, "$Source")
.self()
.with(relation, "$Source")
.src("_")
.each([](flecs::entity entity) {
std::cout << entity.name() << std::endl;
});
std::cout << std::endl << "Query Up and Self:" << std::endl;
ecs.query_builder()
.with(flecs::ChildOf, "$Source")
.self()
.up()
.with(relation, "$Source")
.src("_")
.each([](flecs::entity entity) {
std::cout << entity.name() << std::endl;
});
return 0;
}
Output:
Query Up:
Grandchild
Query Self:
Child
Sibling
Query Up and Self:
Child
SiblingExpected behavior Query for up and self should return Grandchild as well here.
Additional context Tested on latest master (9f5152c141077f5b2ca5f24ee7a667ce0b5108e8)
Source: SanderMertens/flecs