views:

68

answers:

2

Since there isn't respositories for value objects. How can I load all value objects?

Suppose we are modeling a blog application and we have this classes:

  • Post (Entity)
  • Comment (Value object)
  • Tag (Value object)
  • PostsRespository (Respository)

I Know that when I save a new post, its tags are saving with it in the same table. But how could I load all tags of all posts. Has PostsRespository got a method to load all tags? I usually do it, but I want to know others opinions

+1  A: 

I am currently working through a similar example. Once you need to uniquely refer to tags they are no long simple value objects and may continue to grow in complexity. I decided to make them their own entities and create a separate repository to retrieve them. In most scenarios they are loaded or saved with the post but when they are required alone the other repository is used.

I hope this helps.

EDIT: In part thanks to this post I decided to restructure my application slightly. You are right that I probably was incorrectly making tags an entity. I have since changed my application so that tags are just strings and the post repository handles all the storage requirements around tags. For operations that need posts the tags are loaded with them. For any operation that just requires tags or lists of tags the repository has methods for that.

smaclell
Thanks for the answer. So you have an TagsRepository. Do you have a Tags table in database too?
yeraycaballero
I actually have not decided on the database yet. I probably will not have a separate database and am strongly considering an object or document database solution like mongo or couch.
smaclell
+1  A: 

I'm looking for a better solution for this question and I found this post:

http://gojko.net/2009/09/30/ddd-and-relational-databases-the-value-object-dilemma/

This post explain very well why there is a lot of confusion with value objects and databases. Here you are phrase which liked me too much:

  • "Persistence is not an excuse to turn everything to entities."

Gojko Adzic, give us three alternatives to save our value objects.

yeraycaballero