setup usage_rules
This commit is contained in:
31
.claude/skills/ash-framework/references/exist_expressions.md
Normal file
31
.claude/skills/ash-framework/references/exist_expressions.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# Exists Expressions
|
||||
|
||||
Use `exists/2` to check for the existence of records, either through relationships or unrelated resources:
|
||||
|
||||
### Related Exists
|
||||
|
||||
```elixir
|
||||
# Check if user has any admin roles
|
||||
Ash.Query.filter(User, exists(roles, name == "admin"))
|
||||
|
||||
# Check if post has comments with high scores
|
||||
Ash.Query.filter(Post, exists(comments, score > 50))
|
||||
```
|
||||
|
||||
### Unrelated Exists
|
||||
|
||||
```elixir
|
||||
# Check if any profile exists with the same name
|
||||
Ash.Query.filter(User, exists(Profile, name == parent(name)))
|
||||
|
||||
# Check if user has any reports
|
||||
Ash.Query.filter(User, exists(Report, author_name == parent(name)))
|
||||
|
||||
# Complex existence checks
|
||||
Ash.Query.filter(User,
|
||||
active == true and
|
||||
exists(Profile, active == true and name == parent(name))
|
||||
)
|
||||
```
|
||||
|
||||
Unrelated exists expressions automatically apply authorization using the target resource's primary read action. Use `parent/1` to reference fields from the source resource.
|
||||
Reference in New Issue
Block a user