ExTenant.Schema (ExTenant v0.2.1) View Source

To use the Extenant.Schema in your schema modules

  • it injects the belongs_to relationship to the tenant
  • it also raises a compiler error if the tenanted() call was omitted
  • it works with the tenant_id field set in Config.exs

Here is an example

defmodule Post do
  use ExTenant.Schema
  use ExTenant.Changeset

  tenanted_schema "posts" do
    field(:name, :string)
    field(:body, :string)

    tenanted()
  end
end

Link to this section Summary

Functions

injects belongs_to relationship to the tenant model

Replaces Ecto.Schema.embedded_schema/2 - checking whether tenanted() has been called - that injects the belongs_to tenant relationship

Replaces Ecto.Schema.schema/2 - checking whether tenanted() has been called - that injects the belongs_to tenant relationship

Link to this section Functions

injects belongs_to relationship to the tenant model

Example

tenanted_schema "posts" do
  field(:name, :string)
  tenanted()
end
Link to this macro

tenanted_embedded_schema(list)

View Source (macro)

Replaces Ecto.Schema.embedded_schema/2 - checking whether tenanted() has been called - that injects the belongs_to tenant relationship

Link to this macro

tenanted_schema(table_name, list)

View Source (macro)

Replaces Ecto.Schema.schema/2 - checking whether tenanted() has been called - that injects the belongs_to tenant relationship