user4083185
user4083185

Reputation:

Code Organization - Relation or Repository

I'd like to have your opinion about code organization. I have two entities: City and Country. I have an unidirectional ManyToOne between them, Many side is of course City.

Now, I need to get all the cities corresponding to a country. I have two choices:

What is the best way to do so ?

Upvotes: 0

Views: 46

Answers (2)

Bartłomiej Wach
Bartłomiej Wach

Reputation: 1986

It depends on what kind of data and how oftend you need it:

  • if you have the Country object and you need City objects, make it a 2-way ManyToOne
  • if you have the Country id and you need City objects, add a query to repository
  • if you have the Country id and you need City ids, add a query to repository

@Erik's response is also a good view on the subject

Upvotes: 0

Erik
Erik

Reputation: 1057

Depends. If the two entities are in the same Bundle (or in Bundles that require each other's presence), then make it bi-directional, especially if you think this'll be a common thing to search for.

On the other hand, if this is a special case, the entities are in different Bundles, and you don't want to couple them further, then it's better to make a custom method for it.

Upvotes: 2

Related Questions