Skip to content

Commit 9354724

Browse files
committed
Update resource handling
1 parent 66c5900 commit 9354724

2 files changed

Lines changed: 8 additions & 60 deletions

File tree

lib/ash_json_api/resource/info.ex

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -70,42 +70,18 @@ defmodule AshJsonApi.Resource.Info do
7070
Extension.get_opt(resource, [:json_api], :default_fields, nil, true)
7171
end
7272

73-
@doc """
74-
Returns the `relationship_meta` config for the resource.
75-
76-
This is a keyword list keyed by relationship name, where each value is
77-
another keyword list mapping JSON:API meta keys to join resource attributes.
78-
"""
79-
def relationship_meta(resource) do
80-
Extension.get_opt(resource, [:json_api], :relationship_meta, [], true)
81-
end
82-
8373
@doc """
8474
Returns the `relationship_meta_in` config for the resource.
85-
Falls back to `relationship_meta` when not set.
8675
"""
8776
def relationship_meta_in(resource) do
88-
Extension.get_opt(
89-
resource,
90-
[:json_api],
91-
:relationship_meta_in,
92-
relationship_meta(resource),
93-
true
94-
)
77+
Extension.get_opt(resource, [:json_api], :relationship_meta_in, [], true)
9578
end
9679

9780
@doc """
9881
Returns the `relationship_meta_out` config for the resource.
99-
Falls back to `relationship_meta` when not set.
10082
"""
10183
def relationship_meta_out(resource) do
102-
Extension.get_opt(
103-
resource,
104-
[:json_api],
105-
:relationship_meta_out,
106-
relationship_meta(resource),
107-
true
108-
)
84+
Extension.get_opt(resource, [:json_api], :relationship_meta_out, [], true)
10985
end
11086

11187
@doc """
@@ -122,16 +98,6 @@ defmodule AshJsonApi.Resource.Info do
12298
relationship_meta_out(resource)[relationship_name] || []
12399
end
124100

125-
@doc """
126-
Returns the meta-to-join-attribute mapping for the given relationship name.
127-
128-
The result is a keyword list like `[note: :note_on_join]`, where the key is the
129-
JSON:API meta key (as an atom) and the value is the join resource attribute.
130-
"""
131-
def relationship_meta_mapping(resource, relationship_name) do
132-
relationship_meta_in_mapping(resource, relationship_name)
133-
end
134-
135101
defp camelize(name) do
136102
camelized = name |> to_string() |> Macro.camelize()
137103
{first, rest} = String.split_at(camelized, 1)

lib/ash_json_api/resource/resource.ex

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -557,36 +557,15 @@ defmodule AshJsonApi.Resource do
557557
"Whether or not to derive a filter parameter based on the sortable fields of the resource",
558558
default: true
559559
],
560-
relationship_meta: [
561-
type: :keyword_list,
562-
default: [],
563-
doc: """
564-
Backward-compatible shorthand for setting both `relationship_meta_in` and
565-
`relationship_meta_out` to the same mapping.
566-
567-
Configures how join-table fields are mapped via JSON:API `meta` on relationship
568-
resource identifiers for many_to_many relationships.
569-
570-
The value is a keyword list keyed by relationship name, where each value is
571-
another keyword list mapping JSON:API meta keys to join resource attributes.
572-
573-
For example, to expose a `:note` attribute on the join resource for the
574-
`:tags` relationship:
575-
576-
relationship_meta [
577-
tags: [note: :note]
578-
]
579-
580-
This enables both reading and writing join-table fields via the `meta` object
581-
on relationship resource identifiers for that relationship.
582-
"""
583-
],
584560
relationship_meta_in: [
585561
type: :keyword_list,
586562
default: [],
587563
doc: """
588564
Configures how incoming JSON:API `meta` keys on relationship resource identifiers
589565
map to join resource attributes for many_to_many relationship writes.
566+
567+
Use together with `relationship_meta_out` for reads. Each relationship you want to
568+
support must declare both mappings explicitly.
590569
"""
591570
],
592571
relationship_meta_out: [
@@ -595,6 +574,9 @@ defmodule AshJsonApi.Resource do
595574
doc: """
596575
Configures how join resource attributes map to outgoing JSON:API `meta` keys on
597576
relationship resource identifiers for many_to_many relationship reads.
577+
578+
Use together with `relationship_meta_in` for writes. Each relationship you want to
579+
support must declare both mappings explicitly.
598580
"""
599581
],
600582
field_names: [

0 commit comments

Comments
 (0)