ash-project / ash-project/ash

Allow to specify a read action for a relationship in a load

Open
#711 12 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Elixir
Stars
2.5k
Forks
422
Avg merge
23h 26m
Merged PRs (30d)
46

Description

This is a feature request for a convenient way to specify a read action for a load of a relationship.

Example: Let's say we have a blog with Post and User. Post has `belongs_to :author, User`. And there are two relevant pages - a page with a list of all posts and a page for a single post. In both cases when posts are read we want to load their authors too. But in a list an author is represented only by a name while on a post page we want to show their avatar, small bio/about paragraph, maybe posts count, stuff like that.

The problem is that currently there is no simple way to do it.

A possible solution is to allow passing action name in load with syntax equal to that for calculations:
```elixir
query |> load(relationship: :action)
query |> load(relationship: [action: args])
query |> load(relationship: [action: {args, nested_loads}])
```

Thoughts?

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the load API and the relationship-loading examples in the issue, then read the surrounding discussion for decisions about the proposed syntax. Done means supporting relationship loads with an action, action arguments, and nested loads for the listed forms.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.