First, let's create a Scalar to represent individual stock items. Think of a Scalar as a reusable data building block - like Lego pieces that can be combined into larger structures. Unlike a full Model that has its own database collection, a Scalar is embedded within other models. In our case, the Stock scalar will be used inside the Inventory model.
Use the CLI to generate the scalar structure:
Now define the Stock scalar with the item type and quantity tracking:
Let's understand the Stock scalar structure:
📦StockType: An enum combining yogurt ice cream with all available toppings. This allows tracking inventory for all product types in one system.
📊totalQty / currentQty: Track both the starting amount and current remaining quantity. This helps calculate usage and identify when restocking is needed.
Add dictionary entries for the scalar. Notice how we reuse the topping translations from the icecreamOrder dictionary: