PgRest.SchemaGraph.Relationship (PgRest v0.2.0)

Copy Markdown View Source

One directed relationship between two registered resources, shaped like PostgREST's schema-cache relationships.

Columns are database column names, in constraint order. source_columns[i] pairs with target_columns[i].

  • :m2o - source holds the foreign key
  • :o2m - target holds the foreign key
  • :o2o - one-to-one in either direction (the foreign key columns are unique)
  • :m2m - through junction; source_columns / target_columns are the key columns of the two resources, junction.source_columns / junction.target_columns the junction columns that reference them, and constraint is the junction table name and junction.module the registered resource of the junction table

assoc is the Ecto association (or explicit declaration) name on source, when there is one.

Summary

Functions

Whether the target is one row per source row (:m2o, :o2o) rather than a set.

Types

junction()

@type junction() :: %{
  module: module(),
  table: String.t(),
  schema: String.t(),
  source_columns: [String.t()],
  target_columns: [String.t()],
  constraints: {String.t(), String.t()}
}

kind()

@type kind() :: :m2o | :o2m | :o2o | :m2m

t()

@type t() :: %PgRest.SchemaGraph.Relationship{
  assoc: atom() | nil,
  constraint: String.t(),
  junction: junction() | nil,
  kind: kind(),
  source: module(),
  source_columns: [String.t()],
  target: module(),
  target_columns: [String.t()]
}

Functions

to_one?(relationship)

@spec to_one?(t()) :: boolean()

Whether the target is one row per source row (:m2o, :o2o) rather than a set.