Shyam Ramineni
Shyam Ramineni

Reputation: 51

Grails domain class design for ERP requirement

I am having to two domain classes Order and Stock. When stock is sold I am creating an entry in the child table StockOrder which contains information about the Order(order_id) and Stock(stock_id) and noOfStockSold.

In my current design I coded the StockOrder close to Stock table. You can see this below.

Class Stock {
    String stockName
    BigDecimal quantity
    List stockOrderList
    static hasMany = [stockOrderList: StockOrder]
}

class StockOrder {
    Stock stock
    Order order
    BigDecimal noOfStockSold
    static belongsTo = [Stock]
}

class Order {

    List saleLineItemList
    static hasMany = [saleLineItemList: SaleLineitem]
}
  1. Am I doing to correctly from ERP prespective. How to relate Order to Stock sold?
  2. Is it ok if I tie StockOrder to Order also by doing static belongsTo = [Stock,Order]
  3. Is there any better way of doing it or any improvements?

Upvotes: 0

Views: 315

Answers (1)

Jarred Olson
Jarred Olson

Reputation: 3243

I would start by reading these:

http://grails.org/doc/2.0.x/ref/Domain%20Classes/belongsTo.html http://grails.org/doc/2.0.x/ref/Domain%20Classes/hasMany.html

Basically you use the belongsTo and hasMany to describe bi-directional relationships. This allows you to cascade delete objects if you so desire. I would imagine in an ERP system that you wouldn't want cascading functionality because if you delete a Stock you probably don't want to delete all the associated StockOrder. I would probably keep the hasMany side of the relationship and remove the belongsTo since you're already associating a StockOrder to a Stock and an Order.

Upvotes: 2

Related Questions