[ { "description": "Lineage: the self-referential base edge (entity.parent_id -> entity) is always read from the parent down", "database": { "puncs": [], "enums": [], "relations": [ { "id": "44444444-4444-4444-4444-444444444441", "type": "relation", "constraint": "fk_entity_parent", "source_type": "entity", "source_columns": [ "parent_id" ], "destination_type": "entity", "destination_columns": [ "id" ] } ], "types": [ { "name": "entity", "hierarchy": [ "entity" ], "fields": [ "id", "type", "archived", "created_at", "parent_id", "ancestors" ], "grouped_fields": { "entity": [ "id", "type", "archived", "created_at", "parent_id", "ancestors" ] }, "field_types": { "id": "uuid", "type": "text", "archived": "boolean", "created_at": "timestamptz", "parent_id": "uuid", "ancestors": "uuid[]" }, "schemas": { "entity": { "type": "object", "properties": { "id": { "type": "string", "format": "uuid" }, "type": { "type": "string" }, "archived": { "type": "boolean" }, "created_at": { "type": "string", "format": "date-time" }, "created": { "type": "boolean" }, "parent_id": { "type": [ "string", "null" ], "format": "uuid" }, "ancestors": { "type": "array", "items": { "type": "string", "format": "uuid" } } } } }, "lookup_fields": [], "historical": true, "relationship": false, "variations": [ "entity", "invoice", "invoice_line" ] }, { "name": "invoice", "hierarchy": [ "entity", "invoice" ], "fields": [ "id", "type", "total", "archived", "created_at", "parent_id", "ancestors" ], "grouped_fields": { "invoice": [ "id", "type", "total" ], "entity": [ "id", "type", "archived", "created_at", "parent_id", "ancestors" ] }, "field_types": { "id": "uuid", "type": "text", "archived": "boolean", "created_at": "timestamptz", "parent_id": "uuid", "ancestors": "uuid[]", "total": "numeric" }, "schemas": { "invoice": { "type": "entity", "properties": { "total": { "type": "number" }, "lines": { "type": "array", "items": { "type": "invoice_line" } }, "first_line": { "type": "invoice_line" } } } }, "lookup_fields": [], "historical": true, "relationship": false, "variations": [ "invoice" ] }, { "name": "invoice_line", "hierarchy": [ "entity", "invoice_line" ], "fields": [ "id", "type", "price", "archived", "created_at", "parent_id", "ancestors" ], "grouped_fields": { "invoice_line": [ "id", "type", "price" ], "entity": [ "id", "type", "archived", "created_at", "parent_id", "ancestors" ] }, "field_types": { "id": "uuid", "type": "text", "archived": "boolean", "created_at": "timestamptz", "parent_id": "uuid", "ancestors": "uuid[]", "price": "numeric" }, "schemas": { "invoice_line": { "type": "entity", "properties": { "price": { "type": "number" } } } }, "lookup_fields": [], "historical": true, "relationship": false, "variations": [ "invoice_line" ] } ] }, "tests": [ { "description": "An array of children joins child.parent_id = parent.id, never the other way", "action": "query", "schema_id": "invoice", "expect": { "success": true, "sql": [ [ "((SELECT jsonb_strip_nulls((", " SELECT jsonb_build_object(", " 'id', invoice_2.id,", " 'type', invoice_2.type,", " 'archived', entity_1.archived,", " 'created_at', entity_1.created_at,", " 'parent_id', entity_1.parent_id,", " 'ancestors', entity_1.ancestors,", " 'total', invoice_2.total,", " 'lines', (", " SELECT COALESCE(jsonb_agg(jsonb_build_object(", " 'id', invoice_line_4.id,", " 'type', invoice_line_4.type,", " 'archived', entity_3.archived,", " 'created_at', entity_3.created_at,", " 'parent_id', entity_3.parent_id,", " 'ancestors', entity_3.ancestors,", " 'price', invoice_line_4.price", " )), '[]'::jsonb)", " FROM agreego.entity entity_3", " JOIN agreego.invoice_line invoice_line_4 ON invoice_line_4.id = entity_3.id", " WHERE", " NOT entity_3.archived", " AND entity_3.parent_id = entity_1.id", " ),", " 'first_line', (", " SELECT jsonb_build_object(", " 'id', invoice_line_6.id,", " 'type', invoice_line_6.type,", " 'archived', entity_5.archived,", " 'created_at', entity_5.created_at,", " 'parent_id', entity_5.parent_id,", " 'ancestors', entity_5.ancestors,", " 'price', invoice_line_6.price", " )", " FROM agreego.entity entity_5", " JOIN agreego.invoice_line invoice_line_6 ON invoice_line_6.id = entity_5.id", " WHERE", " NOT entity_5.archived", " AND entity_5.parent_id = entity_1.id", " LIMIT 1", " )", " )", " FROM agreego.entity entity_1", " JOIN agreego.invoice invoice_2 ON invoice_2.id = entity_1.id", " WHERE", " NOT entity_1.archived", "))))" ] ] } } ] } ]