View Source Bonfire.Social.Edges (Bonfire v0.9.10-classic-beta.169)
Shared helpers for modules that implemented Edges to mutate or query them, preload relevant associations, etc.
This is a shared context for Bonfire.Data.Edges.Edge
, which has these fields:
- id: primary key which matches the related Activity
- subject: the who (eg. a user)
- table: what kind of action (eg. references Like or Follow in
Needle.Table
...) - object: the what (eg. a specific post)
Summary
Functions
Prepares a full changeset for the given schema, subject, verb, object, and options.
Prepares a basic schema, with the schema type as top-level and an Egde assoc
Prepares a changeset with creator but no caretaker, which avoids the edge being deleted when subject is deleted.
Prepares a changeset with Acls, Activities and FeedActivities
Prepares a changeset with creator but no caretaker, which avoids the edge being deleted when subject is deleted. Also includes Acls, Activities and FeedActivities.
Counts the edges for the given type, filters or object, and options.
Counts the edges for the given type, subject, object, and options.
Deletes edges by subject, type, and object
Deletes edges where the given user is the object.
Deletes edges where the given user is the subject.
Checks if an edge exists with the given schema/context, subject, and object.
Retrieves the edge with either
Inserts a changeset with optional subject and object.
Inserts a new edge with the given schema, subject, verb, and object.
Retrieves the last edge of a given type, subject, and object from the database.
Retrieves the date of the last edge of a given type, subject, and object from the database.
TODOC
Functions
Prepares a full changeset for the given schema, subject, verb, object, and options.
Examples
iex> changeset(MySchema, %User{id: 1}, :like, %Post{id: 2}, [])
%Ecto.Changeset{}
Prepares a basic schema, with the schema type as top-level and an Egde assoc
iex> changeset_base(Like, %User{id: 1}, %Post{id: 2}, [])
%Ecto.Changeset{}
iex> changeset_base(Follow, %User{id: 1}, %User{id: 2}, [])
%Ecto.Changeset{}
iex> changeset_base({Request, Follow}, %User{id: 1}, %User{id: 2}, [])
%Ecto.Changeset{}
Prepares a changeset with creator but no caretaker, which avoids the edge being deleted when subject is deleted.
Examples
iex> changeset_base_with_creator(MySchema, %User{id: 1}, %Post{id: 2}, [])
%Ecto.Changeset{}
Prepares a changeset with Acls, Activities and FeedActivities
changeset_without_caretaker(schema, subject, verb, object, options)
View SourcePrepares a changeset with creator but no caretaker, which avoids the edge being deleted when subject is deleted. Also includes Acls, Activities and FeedActivities.
Examples
iex> changeset_without_caretaker(MySchema, %User{id: 1}, :like, %Post{id: 2}, [])
%Ecto.Changeset{}
Counts the edges for the given type, filters or object, and options.
Examples
> count(:like, %Post{id: 2}, [])
42
Counts the edges for the given type, subject, object, and options.
Examples
> count_for_subject(:like, %User{id: 1}, %Post{id: 2}, [])
42
Deletes edges by subject, type, and object
Examples
iex> delete_by_both(%User{id: 1}, MySchema, %User{id: 2})
:ok
Deletes edges where the given user is the object.
Examples
iex> delete_by_object(%User{id: 1})
:ok
Deletes edges where the given user is the subject.
Examples
iex> delete_by_subject(%User{id: 1})
:ok
Checks if an edge exists with the given schema/context, subject, and object.
Examples
> exists?(MySchema, %User{id: 1}, %Post{id: 2}, [])
true
TODOC
Retrieves the edge with either:
- a schema/context, subject, and object(s)
- a schema/context, filters, and options
Examples
> get(MySchema, %User{id: 1}, %Post{id: 2})
> get(MySchema, [%{subject: %User{id: 1}}], [])
Inserts a changeset with optional subject and object.
Examples
iex> insert(%Changeset{}, %User{id: 1}, %Post{id: 2})
{:ok, %Edge{}}
Inserts a new edge with the given schema, subject, verb, and object.
Examples
> insert(MySchema, %User{id: 1}, :like, %Post{id: 2}, [])
{:ok, %Edge{}}
Retrieves the last edge of a given type, subject, and object from the database.
Examples
iex> last(MySchema, %User{id: 1}, %Post{id: 2}, [])
Retrieves the date of the last edge of a given type, subject, and object from the database.
Examples
> last_date(:like, %User{id: 1}, %Post{id: 2}, [])
~N[2023-07-25 12:34:56]
TODOC
TODOC