nordborg wrote:
Quote:
Another approach for this would be to have separate collections containing the current prices and all prices. I kinda would like this approach more: when I need all the prices, I could say Product.getPrices() and when I need only the current prices, I could say Product.getCurrentPrices() without any special code in my data access layer. Is this possible and if yes, how I can do it?
It should be possible. All collection mappings support a "where" attribute that can be used as a "static" filter. Note that this is not something that can be enabled/disabled programmatically, but I guess that would suit you perfectly in this case.
Thanks for your answer. If I understood correctly, I could do this, then:
Code:
<class name="Product" table="products">
...
<set name="prices" order-by="price">
<key column="product_id" />
<one-to-many class="Price" />
</set>
<set name="currentPrices" order-by="price" where="is_current = true">
<key column="product_id" />
<one-to-many class="Price" />
</set>
</class>
Now I could create getPrices() and getCurrentPrices() to Product class. If I'm right, this doesn't need anything special in the Price side of the association (Price has a property product, which tells the product the price is intended for)?
However, if I have something like Product.addPrice(Price) in the Product class and it adds the price to
prices AND
currentPrices, could it result in problems when saving the product?
Best regards,
Mikko Nylén