He Dominik, You can add an 'orderBy' property to your Company.openingHours<http://doctrine-orm.readthedocs.org/en/latest/tutorials/ordered-associations.html>. Then you can use $company->getOpeningHours(), which would return them ordered as instructed, so no need for Repositories here.
One note of thought though: you have modeled 'OpeningHour' as an Entity, while in my opinion, it should be a ValueObject. An OpeningHour can be considered a TimeInterval, for example: 09:00-17:00. Sometimes Companies have multiple OpeningHours per day: - 09:00-12:00 - 13:00-17:00 Which makes it a collection of TimeIntervals. Now every weekday might have such a collection. You could make a custom DBAL type 'OpeningHour' which contains the weekday number and the collection of TimeIntervals: - weekday: 1-7 - timeIntervals: array(TimeInterval1, TimeIntervalN) And what about holidays? A pragmatic approach would be to introduce a 'weekday 8', which represents a Holiday. The suggested custom DBAL type 'OpeningHour' would be serialized to a string and stored in the same table as your Companies, which reduces the amount of JOINS when fetching your Companies, but increases the required effort to deserialize all the OpeningHours during hydration (doing this 'lazy' is not that easy, but for easy deserializations the amount of required CPU is limited). We once made a decision to use collections of CRON expressions to serialize/deserialize the TimeIntervals. This makes it very flexible, but also complex and computational intensive, so a refactor to a simpler format like 'weekdayX|HH:MM-HH:MM,HH:MM-HH:MM,...' etc, is somewhere on the to-do list ;). Maybe you can share your progress on this field? Native support for ValueObjects is work-in-progress, some nice reads: http://docs.doctrine-project.org/en/2.0.x/reference/limitations-and-known-issues.html#value-objects http://rosstuck.com/persisting-value-objects-in-doctrine/ http://russellscottwalker.blogspot.nl/2013/11/entities-vs-value-objects-and-doctrine-2.html Cheers! On 11 April 2014 08:29, Dominik Barann <[email protected]> wrote: > Hey, > > I have a company entity with a one to many association to its opening hour > entities. Now i want to receive the opening hours of a company ordered by > weekday. Is it ok to write a method called findOpeningHours(Company > $company) in the company repository or should it be a method called > findAllByCompany(Company $company) in the opening hour repository? > > In case of using the opening hour repository > I use a service layer in which i inject the different repository > instances. So in my CompanyService i have a method called > getOpeningHours(Company $company) which uses the opening hour repository to > receive them. So i would have to inject all the repositories for the > different associations of the company to my service. That could be a lot of > :) > > So would it be the best way to handle all these associations within the > company repository or is there a problem which i can't see there yet? > > Thanks in advance > Dominik > > -- > You received this message because you are subscribed to the Google Groups > "doctrine-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/doctrine-user. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "doctrine-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/doctrine-user. For more options, visit https://groups.google.com/d/optout.
