Insert into Database without Form

Is there a way to insert into the database a new entry without a form. i.e. a user does a form action which creates an entity and then I need to update the user to attach them to that new entity.
7 Replies
dj_goku
dj_goku3y ago
By entry, do you mean to insert a resource?
harry
harryOP3y ago
yeah
ZachDaniel
ZachDaniel3y ago
Have you use Ash outside the context of phoenix forms so far?
harry
harryOP3y ago
A little But I wondered if there was a flow syntax
ZachDaniel
ZachDaniel3y ago
There is an Ash.Flow which will run a series of steps, but you can also just invoke actions directly i.e user |> Ash.Changeset.for_update(...) |> Api.update!() and if you want to do it in an action (i.e relate the current actor)
action :create do
change relate_actor(:owner)
end
action :create do
change relate_actor(:owner)
end
then you can create the form with the current user, i.e Form.for_create(..., actor: socket.assigns.current_user)
harry
harryOP3y ago
cool thanks sorry for the delayed reply I have been busy with other stuff and not had chance to look at this since
ZachDaniel
ZachDaniel3y ago
Not a problem 🙂 you do what you gotta do 😁

Did you find this page helpful?