-
Notifications
You must be signed in to change notification settings - Fork 1
Home
The _id field is an unique and auto-generated by API, which can not be changed = read-only.
This field is used in cases there is a need of identifying an object, such as reading, updating and deleting object information, as well as in foreign field and arrays inside an object, which names contains an "_id"-word.
Foreign field is a field, which links different objects together. For example Player can join a Clan, so the Player object will have clan_id field, which is a foreign field.
The name of a foreign field always starts with a name of an object (=collection) to which it is pointing (=belongs). For example clan_id = _id of the Clan to which particular collection belongs to, so if a Player object has clan_id, it means that Player belongs to (=joined to) Clan, or if Soulhome has clan_id field it means that Soulhome belongs to Clan.
Collection is an abstraction representing one data structure (=object). It is the same thing as a class having a concrete implementation = object. Basically a collection is a table in SQL terms.
One collection may belong to another. In case when there can be only one object belonging to another one = one object may have only one other object, it is called one-to-one relation. For example Soulhome may belong to only one Clan = one Clan may have only one Soulhome. This kind of relations is called one-to-one. Another relation is one-to-many. For example multiple Players may belong to one Clan = one Clan may have multiple Players. Third and last relation is many-to-many.
Below is an ER diagram, which shows all collections can be manipulated via API and which are stored in database. On the diagram can be found fields for each collection except for foreign fields. The underlined fields are fields with unique values.
On the diagram can be found also relations between collections, they are represented by line with rhombus in the middle. On the end of each line can be found one or two symbols. The symbol, which is closer to the collection represents the relation:
One line means that only one object might belong to the opposite collection. For example Player may have only one Clan.
The three lines symbol means that the opposite collection may have multiple objects of it. For example Clan may have multiple Players.
Two symbols on each line represent the relation between collections. For example Clan to Player - one-to-many. Clan to Soulhome - one-to-one.
The second symbol farther from the collection is representing whenever relation is mandatory or optional: line - mandatory and 0 - optional. For example the Player may or may not belong to a Clan, but Soulhome must belong to Clan.
As mentioned previously relations can be mandatory or optional. This may effect the logic of how objects can be created or deleted. For example before it is possible to create a Soulhome there must be a Clan to which it will belong, because the Soulhome can not exist by its own. At the same time Clan can be created without Soulhome existing. So in case of mandatory relations one part always must be optional. However, it is also possible that both sides of the relation are optional in this case there are no restrictions and order of creation does not matter.
In case of deleting an object, some restrictions may also be applied based on the relation between collections. In case of Clan - Soulhome, the Soulhome can be deleted without any actions, but if there is a need to delete the Clan all mandatory objects must be deleted first. So, the Soulhome must be deleted first and only after that Clan can be deleted.
Both creation and deleting logic can be done manually by multiple requests. So, if there is a need to delete a Clan the Soulhome must be deleted on first request and after that the Clan can be deleted. It is possible that API handle this logic automatically (not always a case), but then it is important to keep in mind that the creation and deletion may have side-effects.