4.2. Domain Description

4.2.1. A Blogging System

Let's use a blogging system as the example domain and put together some models that describe it. The blog entry itself is only one component of domain. There are also blog authors, comments on entries, tags on entries, and entry summary data. In everyday language, we might say the domain is composed of the following entities and relationships:

Authors

Each author can make one or more blog entries.

Blogs

Each blog entry is posted by only one main author. Each blog entry can have many comments on it. Each blog entry can have one or more tags associated with it. Each blog entry has summary data about how many comments there are, how many times it has been viewed, etc., kept separate from the content of the blog entry.

Comments

Each of the many comments in the system is attached to only one blog entry.

Tags

Each tag has one or more blog entries associated with it.

Summaries

Each summary is attached to only one blog entry.

4.2.2. Terminology

In Solar terms, we can more formally say the following about the domain:

  • An Author "has many" Blogs. This is a one-to-many relationship.

  • A Blog entry "belongs to" an Author. This is a one-to-one relationship.

  • A Blog entry "has many" Comments. This is a one-to-many relationship.

  • A Blog entry "has many" Tags associated with it, and at the same time "belongs to" those tags. This is a many-to-many relationship.

  • A Blog entry "has one" Summary line. This is a one-to-one relationship.

  • A Comment "belongs to" a Blog entry. This is a one-to-one relationship.

  • A Tag "has many" Blog entries associated with it, and at the same time "belongs to" those blog entries. This is a many-to-many relationship.

Based on that language, we can see the four types of relationships that Solar recognizes in the above example:

  • superior one-to-one relationships (hasOne and the variant hasOneOrNull);

  • superior one-to-many relationships (hasMany);

  • subordinate (reciprocal) one-to-one and many-to-one relationships (belongsTo); and

  • many-to-many relationships.

This many-to-many relationship is called "has and belongs to many" in some systems. In Solar, we call this a hasManyThrough because of the need to go through an AssociationTableMapping model. We will call this association model the Taggings through which Blogs and Tags relate to each other.

4.2.3. Domain Diagram

Here is a graphical diagram of the domain tables and how they relate to each other, using the above terminology.



Local