View Source Bonfire.Social.Edges (Bonfire v0.9.10-classic-beta.156)

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.

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.

Functions

Link to this function

changeset(schema, subject, verb, object, options)

View Source

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{}
Link to this function

changeset_base(schema, subject, object, options)

View Source

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{}
Link to this function

changeset_base_with_creator(schema, subject, object, options)

View Source

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{}
Link to this function

changeset_extra(schema, subject, verb, object, options)

View Source

Prepares a changeset with Acls, Activities and FeedActivities

Link to this function

changeset_without_caretaker(schema, subject, verb, object, options)

View Source

Prepares 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{}
Link to this function

count(type, filters_or_object, opts \\ [])

View Source

Counts the edges for the given type, filters or object, and options.

Examples

> count(:like, %Post{id: 2}, [])
42
Link to this function

count_for_subject(type, subject, object, opts)

View Source

Counts the edges for the given type, subject, object, and options.

Examples

> count_for_subject(:like, %User{id: 1}, %Post{id: 2}, [])
42
Link to this function

delete_by_both(me, schema, object)

View Source

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
Link to this function

edge_module_query(schema_or_context, args)

View Source
Link to this function

exists?(schema_or_context, subject, object, opts)

View Source

Checks if an edge exists with the given schema/context, subject, and object.

Examples

> exists?(MySchema, %User{id: 1}, %Post{id: 2}, [])
true
Link to this function

filters_from_opts(assigns)

View Source

TODOC

Link to this function

get(schema_or_context, subject, object, opts \\ [])

View Source

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}}], [])
Link to this function

get!(schema_or_context, subject, objects, opts \\ [])

View Source
Link to this function

insert(changeset, subject \\ nil, object \\ nil)

View Source

Inserts a changeset with optional subject and object.

Examples

iex> insert(%Changeset{}, %User{id: 1}, %Post{id: 2})
{:ok, %Edge{}}
Link to this function

insert(schema, subject, verb, object, options)

View Source

Inserts a new edge with the given schema, subject, verb, and object.

Examples

> insert(MySchema, %User{id: 1}, :like, %Post{id: 2}, [])
{:ok, %Edge{}}
Link to this function

last(schema_or_context, subject, object, opts)

View Source

Retrieves the last edge of a given type, subject, and object from the database.

Examples

iex> last(MySchema, %User{id: 1}, %Post{id: 2}, [])
Link to this function

last_date(type, subject, object, opts)

View Source

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]
Link to this function

put_edge_assoc(changeset, subject, object)

View Source
Link to this function

put_edge_assoc(changeset, type_of_edge_schema, subject, object)

View Source

TODOC

Link to this function

query_parent(query_schema, filters, opts)

View Source

TODOC