PhoenixKitManufacturing.Schemas.MachineTypeAssignment (PhoenixKitManufacturing v0.3.2)

Copy Markdown View Source

Join table for the many-to-many between machines and machine types.

machine_type_uuid is a soft reference into phoenix_kit_entities (EntityData.uuid for the machine_type entity), not an Ecto.Schema.belongs_to/3 association — machine_type data lives in a separate package with no FK to point at (see PhoenixKitManufacturing.EntitiesRegistry). machine stays a normal association since Machine remains a schema of this module.

Summary

Functions

Builds an insert changeset for a machine ↔ type assignment.

Types

t()

@type t() :: %PhoenixKitManufacturing.Schemas.MachineTypeAssignment{
  __meta__: term(),
  inserted_at: term(),
  machine: term(),
  machine_type_uuid: term(),
  machine_uuid: term(),
  updated_at: term(),
  uuid: term()
}

Functions

changeset(assignment, attrs)

@spec changeset(t(), map()) :: Ecto.Changeset.t()

Builds an insert changeset for a machine ↔ type assignment.

Casts the two FK columns + timestamps and wires assoc_constraint/2 on the machine association so an FK violation comes back as a clean {:error, changeset} instead of raising Ecto.ConstraintError. machine_type_uuid is a soft reference (see moduledoc) — there is no Postgres FK left to violate, so no assoc_constraint/2 for it, but the pair is still covered by idx_machine_type_assignments_unique (core V144) — unique_constraint/2 turns a duplicate-pair insert (e.g. a caller passing the same type uuid twice) into the same clean {:error, changeset} instead of an uncaught Ecto.ConstraintError.