Phil
Phil

Reputation: 4092

RavenDB modelling 1 to many documents

Take this example model:

public class Location
{
    public string Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
}

public class Activity
{
    public string Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
}

The relationship between these documents is a location can have none or many activities. Say London can have Paintball, Go karting etc.

I did thing to put these documents into one document but watching and reading the documentation and blogs, the documents need to be accessed separately. You can imagine a website page for each location listing activities and activity pages giving the details.

Example queries would be:

Using the DenormalizedReference method described at:

http://blogs.sonatribe.com/wayne/2011/07/06/using-denormalized-references-in-ravendb/

(and I did see this but couldn't figure out the syntax or if it does what I need

http://ravendb.net/faq/denormalized-references )

Seems to kind of fit my scenarios. But when making a demo project with the above types I noticed if I changed a location name it didn't change it in the activity. Keeping the documents in sync is a big thing.

So how do I achieve this?

Upvotes: 3

Views: 428

Answers (1)

Ayende Rahien
Ayende Rahien

Reputation: 22956

Phil,

  • have a string LocationId property in the Activity, that would allow you to query for them.
  • it would be easier probably to just store the activities as a collection inside the Location (so they aren't a separate document, but are embedded inside).

Upvotes: 2

Related Questions