I am using PHP with Symfony and Doctrine but my question should be independent from any used language or framework.
Suppose you have an entity Product
with a One-To-Many
relationship to another entity Price
. Price
has (among others) the properties validFrom
and validUntil
. Now I want to know the price of a product on a specific day.
As far as I know this can be accomplished in two ways:
- Create a custom getter on the
Product
entity e.g.getPriceOnDate(date)
. It would cycle through all associated prices until it finds the right one. - Create a repository function that fetches the correct price directly from the database.
Which one of the two approaches are in line with the MVC Best Practices?