title: Prevent deletion of used documents via Security Rules on Firestore
body: <p><strong>CONTEXT:</strong></p>
  
  <p>Suppose there are a products and orders collections on Firestore.</p>
  
  <p>And an order has many products, that is (pseudo-schema):</p>
  
  <pre><code>products {
    name: string
  }
  
  orders {
    items: [{
      product_id: (ref products)
      quantity: number
    }]
  }
  </code></pre>
  
  <p>With these security rules:</p>
  
  <pre><code>match /products/{document=**} {
    allow read, write: if request.auth != null;
  }
  
  match /orders/{document=**} {
    allow read, write: if request.auth != null;
  }
  </code></pre>
  
  <p><strong>SCENARIO:</strong></p>
  
  <p>Now, suppose we have created the product A.</p>
  
  <p>Then, we created the order 1 for the product A.</p>
  
  <p>Next, suppose we delete the product A (which is already being used in the order 1) from the products collection.</p>
  
  <p>This would let the order 1 still referencing the deleted product A.</p>
  
  <p><strong>QUESTION:</strong></p>
  
  <p>Is there a way of writing a Security Rule that prevents the deletion of products that are being used on orders?</p>