BryanJBryce
Ash default create action and keys
I have a question about the behavior of the default create action behavior.
I have a resource: Section, it has a uuid primary key and here is the relevant relationship declaration:
relationships do
belongs_to :exam, App.MCAT.Exam, allow_nil?: false, writable?: true
...
end
When I try to create a Section using the default create action like this:
Section.create!(%{exam_id: exam.id, type: :phys, order: 1, allotted_time_seconds: 60 * 95})
I get an Invalid Input error that says: “relationship exam is required”
I feel like including the id has worked for me before, but I think that is when the id was a primary key.
Is there a way to specify this field with the default create or do I need to make a custom create that accepts exam_id explicitly?
Marked As Solved
zachdaniel
The relationship being writable?: true refers to the relationship being usable with manage_relationship, which they are by default. What you are looking for is attribute_writable?: true, which allows writing to the generated attribute that underpins the belongs_to relationship.
Also Liked
BryanJBryce
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









