{"record":{"id":"9ef34983c4ffa6b1","repo":"hasura/graphql-engine","slug":"the-relationship-relationship-name-on-type-type","errorCode":null,"errorMessage":"The relationship {relationship_name} on type {type_name} defines an aggregate, but aggregates can only be used with array relationships, not object relationships","messagePattern":"The relationship (.+?) on type (.+?) defines an aggregate, but aggregates can only be used with array relationships, not object relationships","errorType":"validation","errorClass":"RelationshipError","httpStatus":null,"severity":"error","filePath":"v3/crates/metadata-resolve/src/stages/object_relationships/error.rs","lineNumber":127,"sourceCode":"        relationship_name: RelationshipName,\n    },\n    #[error(\n        \"The target data connector {data_connector_name} for relationship {relationship_name} on type {type_name} does not support the variables capability\"\n    )]\n    RelationshipTargetDoesNotSupportForEach {\n        type_name: Qualified<CustomTypeName>,\n        relationship_name: RelationshipName,\n        data_connector_name: Qualified<DataConnectorName>,\n    },\n    #[error(\n        \"The target data connector {data_connector_name} for relationship {relationship_name} on type {type_name} has not defined any capabilities\"\n    )]\n    NoRelationshipCapabilitiesDefined {\n        type_name: Qualified<CustomTypeName>,\n        relationship_name: RelationshipName,\n        data_connector_name: Qualified<DataConnectorName>,\n    },\n    #[error(\n        \"The relationship {relationship_name} on type {type_name} defines an aggregate, but aggregates can only be used with array relationships, not object relationships\"\n    )]\n    AggregateIsOnlyAllowedOnArrayRelationships {\n        type_name: Qualified<CustomTypeName>,\n        relationship_name: RelationshipName,\n    },\n    #[error(\n        \"The aggregate defined on the relationship {relationship_name} on type {type_name} has an error: {error}\"\n    )]\n    ModelAggregateExpressionError {\n        type_name: Qualified<CustomTypeName>,\n        relationship_name: RelationshipName,\n        error: models::ModelsError, // ideally, this would return the more accurate\n                                    // `ModelAggregateExpressionError` instead\n    },\n    #[error(\n        \"The source field '{source_field_name}' of type '{source_field_type}' in the relationship '{relationship_name}' on type '{source_type}' cannot be mapped to the target argument '{target_argument_name}' of type '{target_argument_type}' on the target model '{target_model_name}' because their types are incompatible\"\n    )]","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/v3/crates/metadata-resolve/src/stages/object_relationships/error.rs#L109-L145","documentation":"An aggregate definition was found on an object (single-target) relationship, but aggregates only make sense for array relationships where multiple rows can be aggregated.","triggerScenarios":"Adding an `aggregates` block to a relationship that resolves to a single object rather than an array/collection.","commonSituations":"Converting an array relationship to an object relationship and leaving the aggregate config behind; misunderstanding that aggregates apply only to collections.","solutions":["Remove the aggregate definition from the object relationship","If aggregates are intended, change the relationship to an array relationship so aggregation over many rows is valid"],"exampleFix":"// before\nrelationships:\n  author:            # object relationship\n    target: { model: authors }\n    aggregates:\n      count: ...\n// after\nrelationships:\n  author:\n    target: { model: authors }\n# or make it an array relationship:\nrelationships:\n  articles:          # array relationship\n    target: { model: articles }\n    aggregates:\n      count: ...","handlingStrategy":"validation","validationCode":"if (rel.aggregates && rel.kind === 'object') {\n  throw new Error('aggregates are only allowed on array relationships');\n}","typeGuard":null,"tryCatchPattern":"try { await applyMetadata(md); } catch (e) { if (/aggregates can only be used with array relationships/.test(e.message)) { /* remove aggregates or make array */ } throw e; }","preventionTips":["When converting array->object relationships, strip the aggregates block","Codemod lint: aggregates only on relationships with array targets"],"tags":["metadata","relationships","aggregates","validation"],"backgroundTag":"metadata-relationship-validation-failed","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}