# `PgRest.SchemaGraph.Relationship`
[🔗](https://github.com/agoodway/pgrest/blob/v0.2.0/lib/pg_rest/schema_graph/relationship.ex#L1)

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.

# `junction`

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

# `kind`

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

# `t`

```elixir
@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()]
}
```

# `to_one?`

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

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
