ArangoXEcto.create_edge
You're seeing just the function
create_edge
, go back to ArangoXEcto module for more information.
Specs
create_edge(Ecto.Repo.t(), mod(), mod(), keyword()) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
Creates an edge between two modules
This can create an edge collection dynamically if no additional fields are required, otherwise an edge schema needs to be specified.
The collection name can be passed as an option or is obtained from the provided schema, otherwise it is generated dynamically.
Parameters
repo
- The Ecto repo module to use for queriesfrom
- The Ecto Schema struct to use for the from vertexto
- The Ecto Schema struct to use for the to vertexopts
- Options to use
Options
Accepts the following options:
:edge
- A specific edge module to use for the edge. This is required for any additional fields on the edge. Overridescollection_name
.:fields
- The values of the fields to set on the edge. Requiresedge
to be set otherwise it is ignored.:collection_name
- The name of the collection to use.
Examples
iex> ArangoXEcto.create_edge(Repo, user1, user2)
%ArangoXEcto.Edge{_from: "users/12345", _to: "users/54321"}
Create an edge with a specific edge collection name
iex> ArangoXEcto.create_edge(Repo, user1, user2, collection_name: "friends")
%ArangoXEcto.Edge{_from: "users/12345", _to: "users/54321"}
Create a edge schema and use it to create an edge relation
defmodule UserPosts do
use ArangoXEcto.Edge
import Ecto.Changeset
schema "user_posts" do
edge_fields()
field(:type, :string)
end
def changeset(edge, attrs) do
edges_changeset(edge, attrs)
|> cast(attrs, [:type])
|> validate_required([:type])
end
end
iex> ArangoXEcto.create_edge(Repo, user1, user2, edge: UserPosts, fields: %{type: "wrote"})
%ArangoXEcto.Edge{_from: "users/12345", _to: "users/54321"}
Specs
create_edge(Ecto.Repo.t(), mod(), mod(), mod(), map(), keyword()) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
Same as create_edge/4 but specific for custom edge and fields.