Reputation: 51
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]
}
Upvotes: 0
Views: 315
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