{"record":{"id":"7566d5f99ff0f528","repo":"hasura/graphql-engine","slug":"model-fields-cannot-be-used-in-command-based-relat","errorCode":null,"errorMessage":"Model fields cannot be used in command based relationship: {relationship_name:} on type {type_name:}","messagePattern":"Model fields cannot be used in command based relationship: (.+?) on type (.+?)","errorType":"validation","errorClass":"RelationshipError","httpStatus":null,"severity":"error","filePath":"v3/crates/metadata-resolve/src/stages/object_relationships/error.rs","lineNumber":165,"sourceCode":"        source_type: Qualified<CustomTypeName>,\n        relationship_name: RelationshipName,\n        source_field_name: FieldName,\n        source_field_type: QualifiedTypeReference,\n        target_model_name: Qualified<ModelName>,\n        target_argument_name: ArgumentName,\n        target_argument_type: QualifiedTypeReference,\n    },\n    #[error(\"Relationship mappings from value expressions are not supported yet.\")]\n    ValueExpressionMappingsNotSupportedYet,\n    #[error(\n        \"The field path provided in the {location:} of the relationship {relationship_name} on type {type_name} is empty\"\n    )]\n    EmptyFieldPath {\n        location: String,\n        relationship_name: RelationshipName,\n        type_name: Qualified<CustomTypeName>,\n    },\n    #[error(\n        \"Model fields cannot be used in command based relationship: {relationship_name:} on type {type_name:}\"\n    )]\n    ModelFieldCannotBeUsedInCommandRelationship {\n        relationship_name: RelationshipName,\n        type_name: Qualified<CustomTypeName>,\n    },\n    #[error(\"Relationships with nested field paths are not supported yet.\")]\n    NestedFieldPathsNotSupportedYet,\n    #[error(\"{0}\")]\n    CommandError(#[from] commands::CommandsError),\n    #[error(\"{0}\")]\n    ModelError(#[from] models::ModelsError),\n    #[error(\"{0}\")]\n    GraphqlError(#[from] graphql_config::GraphqlConfigError),\n}\n","sourceCodeStart":147,"sourceCodeEnd":181,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/v3/crates/metadata-resolve/src/stages/object_relationships/error.rs#L147-L181","documentation":"A command-based relationship tried to use model fields (fields from the underlying data model) in its mappings. Command relationships can only reference command arguments and type fields, not model fields directly.","triggerScenarios":"Mixing `model_fields`/model-derived fields into a relationship whose target is a CommandName instead of a ModelName.","commonSituations":"Converting a model-based relationship to a command-based one and leaving model field mappings in place; metadata generated by tools that emit a superset of options.","solutions":["Remove the model-field mappings from the command-based relationship","Replace them with mappings from source type fields or command argument mappings","If model fields are required, switch the relationship target back to the model"],"exampleFix":"// before\nrelationships:\n  author:\n    target: { command: AuthorById }\n    model_fields: [author_id]  # not allowed\n// after\nrelationships:\n  author:\n    target: { command: AuthorById }\n    argument_mappings:\n      author_id: author_id","handlingStrategy":"validation","validationCode":"if (rel.target.command && (rel.model_fields?.length)) {\n  throw new Error('model fields cannot be used in a command-based relationship');\n}","typeGuard":null,"tryCatchPattern":"try { await applyMetadata(md); } catch (e) { if (/cannot be used in command based relationship/.test(e.message)) { /* remove model_fields */ } throw e; }","preventionTips":["When retargeting a relationship from model to command, audit and strip model-field mappings","Keep a codemod that cleans relationship keys on target-type changes"],"tags":["metadata","relationships","command","model-fields","validation"],"backgroundTag":"metadata-relationship-validation-failed","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}