forked from AkkomaGang/akkoma
Add some basic changesets.
This commit is contained in:
parent
e12a6d5666
commit
373753e595
4 changed files with 75 additions and 2 deletions
|
|
@ -1,7 +1,7 @@
|
|||
defmodule Pleroma.Object do
|
||||
use Ecto.Schema
|
||||
alias Pleroma.{Repo, Object}
|
||||
import Ecto.Query
|
||||
import Ecto.{Query, Changeset}
|
||||
|
||||
schema "objects" do
|
||||
field :data, :map
|
||||
|
|
@ -9,6 +9,13 @@ defmodule Pleroma.Object do
|
|||
timestamps()
|
||||
end
|
||||
|
||||
def change(struct, params \\ %{}) do
|
||||
changeset = struct
|
||||
|> cast(params, [:data])
|
||||
|> validate_required([:data])
|
||||
|> unique_constraint(:ap_id, name: :objects_unique_apid_index)
|
||||
end
|
||||
|
||||
def get_by_ap_id(ap_id) do
|
||||
Repo.one(from object in Object,
|
||||
where: fragment("? @> ?", object.data, ^%{id: ap_id}))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue