Nested Firestore Data Model

Viewed 53

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).

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.

I currently have the following model

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
}

Although I am not sure this is the best way as the category object is being mapped too many times.

enter image description here

0 Answers
Related