Have I save all channels separately to assign id?
> I am not sure if it's bug or feature, or something else :-)
> I expected channels will have its ids auto assigned.
The channels are part of the Organization document.
Only aggregate roots which you save with session.Store() will get an Id
assigned.
Tobias
> Obviously. But I do not see any advantage of it.
That's not a matter of being an advantage or not. Your store and load
Documents, so they need an Id.
In your sample you load and store Organization instances, not Channel
instances. A Channel can't live outside of an Organization. If it could,
a Channel would be a document of it's own.
Tobias
session.Store(new Organization
{
Id = "organizations/1",
Name = "The First",
Channels = new List<Channel>
{
new Channel { Name = "a" },
new Channel { Name = "b" },
new Channel { Name = "c" },
new Channel {
Name = "d",
Children = new List<Channel> {
new Channel { Name = "e" }
}
},
new Channel { Name = "f" },
new Channel { Name = "h" }
}
});
Now, we have to store each channel separately.
On 28 čvn, 08:27, Ayende Rahien <aye...@ayende.com> wrote:
> What would you expect this to do?
>
> On Sun, Jun 27, 2010 at 11:30 PM, Daniel Steigerwald
> <dan...@steigerwald.cz>wrote:
>
>
>
> > I just rereadhttp://ravendb.net/documentation/docs-document-design.
> It should just assign id not only at stored document, but also for all
> nested documents.
There is no such thing as "nested documents". What you are aiming at
is probably more something like an ORDBMS.
Tobias
What exactly are you trying to do?
With your sample above, keep in mind, that changing a Channel document
will not change the channel item in the Organization document.
Relations between documents are not supported by RavenDB (no joining,
lazy loading or whaever). You've to do this on the client side and then
you would probably only store the channel-Id's in the Organization
document.
Tobias
Do you need to share channels between organisations?
// Ryan
> Tobi, you are not telling me anything what I would not know. Surely
> they are separated. Surely the change of one of organization document
> will not have any impact. I suppose we all know it. We model our data
> to "how it will be used".
This is the missig part for me. You haven't showed how you intend to
use the Channel and Organization classes once you have stored them.
> Maybe you were confused, because I used
> Channel class instance, instead of new { id: .., name: ''}; But I do
> not reason to not reuse existing class which has exactly these
> properties which I need :-)
That's perfectly fine. The question is, what does the channel need an
Id for? Within the Organiztation class Channel is a value object and
just doesn't need an Id.
If you intend to query for Channels, then a channel probably becomes an
Entity. Then it might be appropriate to store a list of channel id's
within Organization, which would introduce some kind of reference that
RavenDB does not support.
If RavenDB would support document references, one consequence would be,
that querying/loading one document must load a bunch of other,
referenced documents. This would introduces "SELECT N+1" problems
probably require a lazy loading solution cascaded deletes not to
mention the impact on sharding etc.
But RavenDB just is a simple document store. There are no relations,
because it's not a relational database.
So if you want to have one document to relate to another one, you have
to handle this on the client side.
Tobias
var chanX = org1.AddChannel("channel x"); // gets id 0
var chanY = org1.AddChannel("channel y");// gets id 1
var chanZ = chanY.AddChannel("channel z"); // gets id 2
var chanA = org2.AddChannel("channel a");// gets id 0
var chanB = org2.AddChannel("channel b"); // gets id 1
Again, they are sequence ids, they only have a meaning with an organization id.
A channel id could be seen as orgID + "/" + channelSequendID.
This channel id could be store with the messages. (the orgID with the
channelSeqID)
HTH
// Ryan
On Mon, Jun 28, 2010 at 4:46 PM, Daniel Steigerwald
> I want to get organization with its channels for one request, then
> send as JSON to the browser, then render it.
> Also, the tree structure is maintained by organization itself. Not by
> channels.
> I am building message system. So each message have to have a reference
> to some channel.
Please give some more details, how you want to use the
Channel.Id-Property in this use case.
If your are sending messages across channels, the sender and receiver
must somehow hook to the same channel. If no organizations share the
same channel, I see no need to make Channel a top-level entity. Still
each channel within an Organization would probably need a unique
identifier, which probably is, what you want. But I would simply use
the "channel name" for this.
Tobias
// Ryan
On Mon, Jun 28, 2010 at 8:21 PM, Daniel Steigerwald