zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

agent_relationship.ex (1924B)


      1 # Zenflows is designed to implement the Valueflows vocabulary,
      2 # written and maintained by srfsh <info@dyne.org>.
      3 # Copyright (C) 2021-2023 Dyne.org foundation <foundation@dyne.org>.
      4 #
      5 # This program is free software: you can redistribute it and/or modify
      6 # it under the terms of the GNU Affero General Public License as published by
      7 # the Free Software Foundation, either version 3 of the License, or
      8 # (at your option) any later version.
      9 #
     10 # This program is distributed in the hope that it will be useful,
     11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 # GNU Affero General Public License for more details.
     14 #
     15 # You should have received a copy of the GNU Affero General Public License
     16 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
     17 
     18 defmodule Zenflows.VF.AgentRelationship do
     19 @moduledoc """
     20 A relationship role defining the kind of association one agent can have
     21 with another.
     22 """
     23 
     24 use Zenflows.DB.Schema
     25 
     26 alias Ecto.Changeset
     27 alias Zenflows.DB.{Schema, Validate}
     28 alias Zenflows.VF.{
     29 	Agent,
     30 	AgentRelationshipRole,
     31 }
     32 
     33 @type t() :: %__MODULE__{
     34 	subject: Agent.t(),
     35 	object: Agent.t(),
     36 	relationship: AgentRelationshipRole.t(),
     37 	# in_scope_of
     38 	note: String.t() | nil,
     39 }
     40 
     41 schema "vf_agent_relationship" do
     42 	belongs_to :subject, Agent
     43 	belongs_to :object, Agent
     44 	belongs_to :relationship, AgentRelationshipRole
     45 	# in_scope_of
     46 	field :note, :string
     47 	timestamps()
     48 end
     49 
     50 @reqr ~w[subject_id object_id relationship_id]a
     51 @cast @reqr ++ [:note] # in_scope_of
     52 
     53 @doc false
     54 @spec changeset(Schema.t(), Schema.params()) :: Changeset.t()
     55 def changeset(schema \\ %__MODULE__{}, params) do
     56 	schema
     57 	|> Changeset.cast(params, @cast)
     58 	|> Changeset.validate_required(@reqr)
     59 	|> Validate.note(:note)
     60 	|> Changeset.assoc_constraint(:subject)
     61 	|> Changeset.assoc_constraint(:object)
     62 	|> Changeset.assoc_constraint(:relationship)
     63 end
     64 end