kamaroly
How to Read Views columns that are not matching Resource attributes?
How to read VIEW columns from a custom statement that don’t exist as attribute on the resource without throwing a Ash.Error.Query.NoSuchAttribute
defmodule MyApp.Members.Member do
use Ash.Resource,
domain: MyApp.Members,
data_layer: AshPostgres.DataLayer
postgres do
table "members"
repo SocialFund.Repo
custom_statements do
statement :view_member_contributions do
# Migrations up
up "CREATE VIEW view_member_contributions
AS SELECT
members.member_number,
contributions.amount AS contributed_amount,
contributions.month AS period
FROM members LEFT JOIN contributions
ON members.id = contributions.member_id;"
# Migration down
down "DROP VIEW IF EXISTS view_member_contributions;"
end
end
end
actions do
read :contribution_report do
prepare build(select: [:member_number, :contributed_amount, :period])
prepare set_context(%{data_layer: %{table: "view_member_contributions"}})
end
end
# Other definitions
end
Marked As Solved
zachdaniel
Creator of Ash
Probably not, TBH. It’s used for a whole bunch of things in Ash proper. You can remove the id from your resource entirely if needed, but not de-select it for a resource that has a primary key.
1
Also Liked
herrybrook
Hi kamaroly,
You can handle columns from a view that aren’t attributes on your resource by either defining virtual attributes marked as read_only: true or creating a custom read action that selects those extra columns. This way, Ash won’t throw a NoSuchAttribute error, but you can still access the data from your view.
1
kamaroly
zachdaniel
Creator of Ash
Popular in Questions
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I’m writing a test for one of the...
New
I am trying to implement my new.html.eex file to create new posts on my website.
new.html.eex:
<h1>Create Post</h1>
<%= ...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
In templates/appointment/index.html.eex:
<%= for appointment <- @appointments do %>
<tr>
<td><%= appoi...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
Hi! May someone helps me, please!
I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Other popular topics
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
Hi!
Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
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
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









