---
apiVersion: data-spec/v1
id: quote-product-relationship-names-20260422
description: "Correct quote_product__c lookup relationship names to Salesforce-compatible __r values"
issue: "#1624"
created: 2026-04-22
scope: both
status: pending
tables: [_System_Field]
depends_on: []
---

# Quote Product Relationship Names

## Summary

Repairs the runtime field metadata for `quote_product__c.Quote__c` and
`quote_product__c.Product__c` so the stored `RelationshipName` matches
Salesforce's custom-lookup convention: `__c -> __r`.

Without this correction, the UI API emits relationship payloads under `Quote`
and `Product`, while the frontend's metadata-driven lookup flattening expects
`Quote__r` and `Product__r` for custom reference fields. The result is a silent
fallback to raw record IDs on the Quote Product detail page.

The bootstrap source of truth is
`backend/internal/controlplane/packspec/standard_objects_spec.json`.
This spec is `scope: both` because the bootstrap source has been corrected for
fresh environments and this SQL backfills environments that were bootstrapped
before that change.

## Changes

### 1. Normalize `quote_product__c` custom lookup relationship names

```sql
UPDATE _System_Field f
JOIN _System_Object o ON o.Id = f.ObjectId
SET
  f.RelationshipName = CASE f.ApiName
    WHEN 'Quote__c' THEN 'Quote__r'
    WHEN 'Product__c' THEN 'Product__r'
    ELSE f.RelationshipName
  END,
  f.LastModifiedDate = CURRENT_TIMESTAMP
WHERE o.ApiName = 'quote_product__c'
  AND f.ApiName IN ('Quote__c', 'Product__c')
  AND f.IsDeleted = 0
  AND (
    (f.ApiName = 'Quote__c' AND f.RelationshipName <> 'Quote__r')
    OR
    (f.ApiName = 'Product__c' AND f.RelationshipName <> 'Product__r')
  );
```

**Idempotency**: Re-running the spec converges both rows to the same desired
`RelationshipName` values and leaves already-correct rows unchanged.

## Rollback

```sql
UPDATE _System_Field f
JOIN _System_Object o ON o.Id = f.ObjectId
SET
  f.RelationshipName = CASE f.ApiName
    WHEN 'Quote__c' THEN 'Quote'
    WHEN 'Product__c' THEN 'Product'
    ELSE f.RelationshipName
  END,
  f.LastModifiedDate = CURRENT_TIMESTAMP
WHERE o.ApiName = 'quote_product__c'
  AND f.ApiName IN ('Quote__c', 'Product__c')
  AND f.IsDeleted = 0;
```
