Search code examples
grailsgrails-orm

Grails Inventory Desgin


I have these domain class:

class Product {

Manufacture manufacture
Model model
Category category
int price
String productCondition
String productDescription
}

class Manufacture {

String manufactureName

static hasMany = [products:Product, models:Model]
}

class Model {

Manufacture manufacture
String modelName

static hasMany = [products:Product]
}

class Category {

String categoryName
static hasMany = [products:Product];
}

I am wondering if I need a Manufacture class, Model class, and Category class or if I can just use a String manufacture, etc.. Is there any advantage to having those additional domain classes than just having String manufacture, etc when it comes to searching? Say I want all products that are manufactured by Ford, or all products that are category car. I am confused on when I should make a domain class vs just using a field.

Thanks


Solution

  • The choice between one solution or the other one depends on how you plan to query the application and adapt it to future changes.

    You could use only a Product domain class and with the appropriate database indexes on manufacture, model and category String fields the queries would go fast. But with this approach you can not evolve easily your domain to add new fields to manufacture, model and category.

    I always prefer the domain class solution because I don't know how the application is going to evolve.

    And intermediate solution can be use embedded domain classes.