Relationships

Relationships are a fundamental part of modeling content in TakeShape they allow content items to reference one another. You can think of them as foreign keys in RDBMS or Associations from Rails, but as you'll see TakeShape's relationships are much more powerful. 

Single Relationships

When creating a relationship the first step is to choose what content type you want to allow in the relationship: 

Unlike traditional foreign keys TakeShape allows you to create relationships that allow references to multiple content types.

Multiple Relationships

Multiple relationships can be thought of as an array of single relationships. Not only can content be associated but those as relationships can then be ordered. Ordering makes multiple relationships a very powerful tool when building content that needs to be manually curated.

Reverse Relationships

When a relationship is created a reverse relationship is automatically added to the related content type. For example if you add a relationship to a Book type that points to the Author type, a reverse relationship property called bookSet will automatically appear on Author.

There are cases where the name of this reverse relationship property becomes ambiguous. For example, a Post type with two relationships authors and editors which both point to the Person type. The automatically generated field postSet is now ambiguous because it will contain both authors and editors. The solution is to specify the "Reverse Name" on each relationship. 

In order to disambiguate these relationships set the "Reverse Name" for authors to "authored" and the "Reverse Name"  for editors to  "edited" 

# Ambiguous relatedName not set for author or editor relationships
{
  getAuthor(_id: "author_id") {
    postSet {
      total
      results {
        title
      }
    }
  }
}

# Disambiguated by adding relatedName
{
  getAuthor(_id: "author_id") {
    authored {
      total
      results {
        title
      }
    }
    edited {
      total
      results {
        title
      }
    }
  }
}

Join us

Interested in joining the team as coworker or investor?

contact@takeshape.com