title: Nested Firestore Data Model
body: <p>I am working on a classified ads app (something like craigslist) I am looking at how best to structure the data model using Firestore (NoSQL Database).</p>
  <p>The issue I'm facing is structuring items that have additional fields. For instance, electronic items will have additional fields such as RAM, Storage, etc.</p>
  <p>I currently have the following model</p>
  <pre><code>enum Category: Codable {
      case standard
      case phone(Phone)
      case tv(TV)
  }
  
  struct Item: Codable {
      var document_ID: String? = nil
      var title: String
      var created_at: Int
      var category: Category
  }
  
  struct Phone: Codable {
      var brand: String
      var model: String
      var RAM: String
      var storage: String
  }
  
  struct TV: Codable {
      var size: Int
      var screen_technology: String
  }
  </code></pre>
  <p>Although I am not sure this is the best way as the category object is being mapped too many times.</p>
  <p><a href="https://i.stack.imgur.com/pZ4C1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pZ4C1.png" alt="enter image description here" /></a></p>