Current section

23 Versions

Jump to

Compare versions

12 files changed
+26 additions
-13 deletions
  @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
4 4 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5 5 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6 6
7 + ## [0.22.1](https://github.com/township-agency/ex_teal/compare/v0.22.0...v0.22.1) (2023-06-16)
8 +
9 +
10 + ### Bug Fixes
11 +
12 + * BelongsTo polish ([#193](https://github.com/township-agency/ex_teal/issues/193)) ([99d1c55](https://github.com/township-agency/ex_teal/commit/99d1c551ef3f92d6e69cdf8d22f661484c67aaea))
13 +
7 14 ## [0.22.0](https://github.com/township-agency/ex_teal/compare/v0.21.0...v0.22.0) (2023-06-15)
  @@ -89,12 +89,12 @@
89 89 <<"priv/static/teal/js/18.76fb794e5801472b62b3.chunk.js">>,
90 90 <<"priv/static/teal/js/3.2cbf1b40d964260fb527.chunk.js">>,
91 91 <<"priv/static/teal/js/22.e8afa77e4e57fee52a39.chunk.js.gz">>,
92 - <<"priv/static/teal/js/58d70520d1afd8e430eb.js">>,
93 92 <<"priv/static/teal/js/7.fb02069f3a580bbaf80a.chunk.js">>,
94 93 <<"priv/static/teal/js/4.4b1462d24a37a4f1cfbb.chunk.js">>,
95 94 <<"priv/static/teal/js/22.e8afa77e4e57fee52a39.chunk.js">>,
96 95 <<"priv/static/teal/js/26.a39307866083b9b823df.chunk.js">>,
97 96 <<"priv/static/teal/js/34.c89bf8f11934ad8936b2.chunk.js">>,
97 + <<"priv/static/teal/js/392b533bc167fda6db84.js.gz">>,
98 98 <<"priv/static/teal/js/5.72dd5c93350636478a43.chunk.js">>,
99 99 <<"priv/static/teal/js/28.a133dd37d12aaaa61be4.chunk.js">>,
100 100 <<"priv/static/teal/js/11.9174d212a719cc0e9072.chunk.js">>,
  @@ -105,6 +105,7 @@
105 105 <<"priv/static/teal/js/12.e8db004be91677315299.chunk.js.gz">>,
106 106 <<"priv/static/teal/js/8.44d739e242d2abc12a4b.chunk.js">>,
107 107 <<"priv/static/teal/js/17.47a85995707949a4a3dc.chunk.js">>,
108 + <<"priv/static/teal/js/392b533bc167fda6db84.js">>,
108 109 <<"priv/static/teal/js/24.833e29c2b12d51594eb3.chunk.js">>,
109 110 <<"priv/static/teal/js/21.f1c8631ee2a25c03dc9a.chunk.js.gz">>,
110 111 <<"priv/static/teal/js/4.4b1462d24a37a4f1cfbb.chunk.js.gz">>,
  @@ -117,7 +118,6 @@
117 118 <<"priv/static/teal/js/30.182477fc257193aeffe3.chunk.js.gz">>,
118 119 <<"priv/static/teal/js/30.182477fc257193aeffe3.chunk.js">>,
119 120 <<"priv/static/teal/js/27.c73fa88509d1880fc1e8.chunk.js">>,
120 - <<"priv/static/teal/js/58d70520d1afd8e430eb.js.gz">>,
121 121 <<"priv/static/teal/js/13.e72b59b828b67b4ca6ce.chunk.js">>,
122 122 <<"priv/static/teal/js/32.594912d71a9c189dc2b2.chunk.js">>,
123 123 <<"priv/static/teal/js/7.fb02069f3a580bbaf80a.chunk.js.gz">>,
  @@ -208,4 +208,4 @@
208 208 {<<"optional">>,false},
209 209 {<<"repository">>,<<"hexpm">>},
210 210 {<<"requirement">>,<<"~> 1.0">>}]]}.
211 - {<<"version">>,<<"0.22.0">>}.
211 + {<<"version">>,<<"0.22.1">>}.
  @@ -56,7 +56,7 @@ defmodule ExTeal.FieldFilter.BelongsTo do
56 56 Map.merge(defaults, %{
57 57 belongs_to_key: rel.owner_key,
58 58 belongs_to_relationship: related_resource.uri(),
59 - searchable: Map.get(field.options, :searchable, false)
59 + searchable: true
60 60 })
61 61
62 62 _ ->
  @@ -86,6 +86,7 @@ defmodule ExTeal.Resource.Index do
86 86 |> Records.preload(resource)
87 87 |> Index.query_by_related(conn.params, resource)
88 88 |> Index.search(conn.params, resource)
89 + |> Index.sort(conn.params, resource)
89 90 |> execute_query(conn, resource, :related)
90 91 |> resource.render_related(resource, conn)
91 92 end
  @@ -176,8 +177,13 @@ defmodule ExTeal.Resource.Index do
176 177
177 178 def sort(query, %{"order_by" => field, "order_by_direction" => dir}, resource)
178 179 when not is_nil(field) and not is_nil(dir) do
179 - fields = Fields.all_fields(resource)
180 - field_struct = Enum.find(fields, &(&1.attribute == field))
180 + new_schema = struct(resource.model(), %{})
181 +
182 + field_struct =
183 + resource
184 + |> Fields.all_fields()
185 + |> Enum.find(&(&1.attribute == field))
186 + |> then(& &1.type.apply_options_for(&1, new_schema, %{}, :index))
181 187
182 188 handle_sort(query, field_struct, String.to_existing_atom(field), dir)
183 189 end
  @@ -189,8 +195,8 @@ defmodule ExTeal.Resource.Index do
189 195 end
190 196 end
191 197
192 - defp handle_sort(query, %Field{type: BelongsTo}, field, dir) do
193 - handle_sort(query, nil, String.to_existing_atom("#{Atom.to_string(field)}_id"), dir)
198 + defp handle_sort(query, %Field{type: BelongsTo} = field, _field_key, dir) do
199 + handle_sort(query, nil, field.options.belongs_to_key, dir)
194 200 end
195 201
196 202 defp handle_sort(query, %Field{virtual: true}, f, "asc") do
  @@ -6,7 +6,7 @@ defmodule ExTeal.MixProject do
6 6 def project do
7 7 [
8 8 app: :ex_teal,
9 - version: "0.22.0",
9 + version: "0.22.1",
10 10 elixir: "~> 1.12",
11 11 start_permanent: Mix.env() == :prod,
12 12 build_embedded: Mix.env() == :prod,
Loading more files…