View Source Resourceful.Type.Relationship (Resourceful v0.1.4)

Relationships come in one of two types: :one or :many. Things like foreign keys and how the relationships map are up to the underlying data source. For the purposes of mapping things in Resourceful, it simply needs to understand whether it's working with a single thing or multiple things.

A natural opinion of relationships is that graphing is simply not allowed on :many relationships. What this means is that you can only do graphed filters and sorts against :one relationships.

For example, a song can sort and filter on an album and its artist because a song has one album which has one artist. The reverse is not possible because an artist has many albums which have many songs. Sorting and filtering on relationships makes sense when data can be represented as a table. In situations where it's a tree, multiple queries are necessary and the client is responsible for putting the data together.

It makes sense to filter and sort a song by an album or artist's attribute. It does not make sense to sort an artist by a song's attribute.

Link to this section Summary

Functions

Sets the name for the relationship. This is the "edge" name that clients will interact with. It can be any string as long as it doesn't contain dots. This will also serve as its key name if used in conjunction with a Resourceful.Type which is important in that names must be unique within a type.

Creates a new relationship, coerces values, and sets defaults.

Link to this section Types

@type type() :: :many | :one

Link to this section Functions

@spec name(
  %Resourceful.Type.Relationship{
    embedded?: term(),
    graph?: term(),
    map_to: term(),
    name: term(),
    related_type: term(),
    type: term()
  },
  String.t() | atom()
) :: %Resourceful.Type.Relationship{
  embedded?: term(),
  graph?: term(),
  map_to: term(),
  name: term(),
  related_type: term(),
  type: term()
}

Sets the name for the relationship. This is the "edge" name that clients will interact with. It can be any string as long as it doesn't contain dots. This will also serve as its key name if used in conjunction with a Resourceful.Type which is important in that names must be unique within a type.

Link to this function

new(type, name, opts \\ [])

View Source
@spec new(type(), String.t() | atom(), keyword()) :: %Resourceful.Type.Relationship{
  embedded?: term(),
  graph?: term(),
  map_to: term(),
  name: term(),
  related_type: term(),
  type: term()
}

Creates a new relationship, coerces values, and sets defaults.