wintermeyer
I have a Reaction resource which is used to store likes and blocks in a social media context (a user can like an other user). I want to create a like action but get the following error. How can I fix this?
iex(12)> like = Animina.Accounts.Reaction
|> Ash.Changeset.for_create(:like, %{sender_id: user2.id, receiver_id: stefan.id})
|> Animina.Accounts.Reaction.create!()
** (Protocol.UndefinedError) protocol Enumerable not implemented for #Ash.Changeset<action_type: :create, action: :like, attributes: %{sender_id: "207a829e-2464-42f7-8257-f4fa482fc7c2", receiver_id: "096da9ff-bcf7-49a1-8cba-f98413f37cab"}, relationships: %{},
The resource:
defmodule Animina.Accounts.Reaction do
@moduledoc """
This is the Reaction module which we use to manage likes, block, etc.
"""
use Ash.Resource,
data_layer: AshPostgres.DataLayer
attributes do
uuid_primary_key :id
attribute :name, :atom do
constraints one_of: [:like, :block]
allow_nil? false
end
create_timestamp :created_at
end
relationships do
belongs_to :sender, Animina.Accounts.User do
allow_nil? false
attribute_writable? true
end
belongs_to :receiver, Animina.Accounts.User do
allow_nil? false
attribute_writable? true
end
end
actions do
defaults [:create, :read, :destroy]
create :like do
accept [:sender_id, :receiver_id]
change set_attribute(:name, :like)
end
end
code_interface do
define_for Animina.Accounts
define :read
define :create
define :destroy
define :by_id, get_by: [:id], action: :read
define :by_sender_id, get_by: [:sender_id], action: :read
define :by_receiver_id, get_by: [:receiver_id], action: :read
end
identities do
identity :unique_reaction, [:sender_id, :receiver_id, :name]
end
postgres do
table "reactions"
repo Animina.Repo
references do
reference :sender, on_delete: :delete
reference :receiver, on_delete: :delete
end
end
end
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex











First Post!- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
benswift
Looks like you are mixing up the changeset-based resource creation flow and the code interface one. Once you have a changeset, you just pipe it into ‘Ash.create!’.
Sorry about the terse reply, typing on my phone right now
Most Liked
zachdaniel
You have a
:likeaction, and so how you call it in code can’t and won’t affect how the JSON:API behaves (which is why Ash is the way that it is).There are three ways to call this
likeaction in code, one of which is no longer available in 3.0. AshJsonApi will be unaffected by your choice here. You should choose #1, but I’m including 2 & 3 informationally.and call it like
YourResource.like(sender_id, receiver_id).NOTE: In 3.0 this can be done in one additional way, where you define the code interface on the domain. It’s not relevant here, see the upgrade guide for more.
You can build a changeset and then call
YourApi.createnotYourApi.Resource.create. This is deprecated in 3.0You can build a changeset and then call
Ash.create. However, this only works if you have configured anapiwhen using the resource, i.euse Ash.Resource, api: Api. (because we have to know the api). This is essentially a compatibility feature to make upgrading to 3.0. Don’t bother with it right now. When you are interested in upgrading to 3.0, the upgrade guide will explain how to make this change.benswift
Oops, sorry – I have been working on v3 stuff and forgot to switch my brain out of that gear