Revert "queryer: don't emit a parent type-bound for reified-relationship properties"

This reverts commit c97e5d75b3.
This commit is contained in:
2026-06-19 15:34:23 -04:00
parent 0509995589
commit 98a9719509
3 changed files with 0 additions and 89 deletions

View File

@ -430,19 +430,6 @@
}
}
},
"single.person": {
"type": "person",
"properties": {
"primary_contact": {
"type": "contact",
"properties": {
"target": {
"type": "email_address"
}
}
}
}
},
"full.person": {
"type": "person",
"properties": {
@ -2538,65 +2525,6 @@
]
]
}
},
{
"description": "Single reified-relationship property (person.primary_contact, type=contact): discriminator + source correlation live INSIDE the subquery; the parent WHERE must NOT get a spurious entity.type bound (regression: reverse reified edges previously emitted entity_1.type = 'contact', excluding every parent)",
"action": "query",
"schema_id": "single.person",
"expect": {
"success": true,
"sql": [
[
"((SELECT jsonb_strip_nulls((",
" SELECT jsonb_build_object(",
" 'id', entity_1.id,",
" 'type', entity_1.type,",
" 'archived', entity_1.archived,",
" 'created_at', entity_1.created_at,",
" 'name', organization_2.name,",
" 'first_name', person_3.first_name,",
" 'last_name', person_3.last_name,",
" 'age', person_3.age,",
" 'primary_contact', (",
" SELECT jsonb_build_object(",
" 'id', entity_4.id,",
" 'type', entity_4.type,",
" 'archived', entity_4.archived,",
" 'created_at', entity_4.created_at,",
" 'is_primary', contact_6.is_primary,",
" 'target', (",
" SELECT jsonb_build_object(",
" 'id', entity_7.id,",
" 'type', entity_7.type,",
" 'archived', entity_7.archived,",
" 'created_at', entity_7.created_at,",
" 'address', email_address_8.address",
" )",
" FROM agreego.entity entity_7",
" JOIN agreego.email_address email_address_8 ON email_address_8.id = entity_7.id",
" WHERE",
" NOT entity_7.archived",
" AND relationship_5.target_id = entity_7.id",
" )",
" )",
" FROM agreego.entity entity_4",
" JOIN agreego.relationship relationship_5 ON relationship_5.id = entity_4.id",
" JOIN agreego.contact contact_6 ON contact_6.id = relationship_5.id",
" WHERE",
" NOT entity_4.archived",
" AND relationship_5.target_type = 'email_address'",
" AND relationship_5.source_id = entity_1.id",
" )",
" )",
" FROM agreego.entity entity_1",
" JOIN agreego.organization organization_2 ON organization_2.id = entity_1.id",
" JOIN agreego.person person_3 ON person_3.id = organization_2.id",
" WHERE",
" NOT entity_1.archived",
"))))"
]
]
}
}
]
}

View File

@ -604,17 +604,6 @@ impl<'a> Compiler<'a> {
if let Some(type_name) = bound_type_name {
// Ensure this type actually exists
if let Some(type_def) = self.db.types.get(&type_name) {
// A reified-relationship property (e.g. invoice.counterparty, person.primary_contact)
// is hydrated by a correlated subquery that joins the relationship table and correlates
// source_id/target_id = parent.id; its discriminators (the relationship subtype and the
// target's type CASE) are constrained INSIDE that subquery. There is no parent-row column
// to bound here — emitting one wrongly constrains the PARENT entity's own `type` column
// (e.g. `entity_1.type = 'counterparty'`), which no parent row satisfies, dropping every
// parent. (Array reified traversals never reach this code: an array prop has no
// bound_type_name.) So skip the bound entirely for relationship-typed properties.
if type_def.relationship {
continue;
}
if let Some(relation) = self.db.relations.get(&edge.constraint) {
let mut poly_col = None;
let mut table_to_alias = "";

View File

@ -1523,12 +1523,6 @@ fn test_queryer_0_16() {
crate::tests::runner::run_test_case(&path, 0, 16).unwrap();
}
#[test]
fn test_queryer_0_17() {
let path = format!("{}/fixtures/queryer.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 17).unwrap();
}
#[test]
fn test_polymorphism_0_0() {
let path = format!("{}/fixtures/polymorphism.json", env!("CARGO_MANIFEST_DIR"));