Releases: woylie/flop
0.26.1
Fixed
- Fixed allowed operators for
Ecto.Enum
fields in Ecto 3.12. - Fixed type expansion when passing values with shortened syntax to
Flop.Filter.expand_type/1
. - Updated documentation example for setting
ecto_type
to parameterized types.
Upgrade Guide
If you pass a parameterized type as ecto_type
option, ensure that you use
Ecto.ParameterizedType.init/2
instead of using the tuple representation as
suggested in the documentation before. The tuple representation is an internal
representation of Ecto and was changed in Ecto 3.12.
[
- ecto_type: {:parameterized, Ecto.Enum, Ecto.Enum.init(values: [:one, :two])}
+ ecto_type: Ecto.ParameterizedType.init(Ecto.Enum, values: [:one, :two])
]
For Ecto.Enum
specifically, you can also use the short syntax
{:ecto_enum, [:one, :two]}
.
0.26.0
Removed
- The previously deprecated tuple syntax for defining join fields has been
removed in favor of a keyword list. - The previously deprecated function
Flop.Schema.field_type/2
was removed in
favor ofFlop.Schema.field_info/2
.
Fixed
- Fixed a compatibility issue with Ecto 3.12 related to the initialization of
theEcto.Enum
type.
Upgrade Guide
Replace the tuple syntax for join fields with a keyword list.
@derive {
Flop.Schema,
join_fields: [
- owner_name: {:owner, :name}
+ owner_name: [
+ binding: :owner,
+ field: :name
+ ]
]
}
0.25.0
0.24.1
0.24.0
0.23.0
0.22.1
0.22.0
This release includes a substantial refactoring to lay the groundwork for the
upcoming adapter feature. While this release contains deprecations and changes,
they are either backward compatible or affect functions that are unlikely to be
used by end users. The primary aim has been to ensure a seamless transition and
maintain compatibility with previous versions.
Added
- Added a
Flop.FieldInfo
struct that contains metadata for a field for use
by adapters. - Added the
Flop.Schema.field_info/2
function, which derives field information
and replaces the previousFlop.Schema.field_type/2
function with a more
standardized and structured output.
Changed
- The Ecto-specific options
alias_fields
,compound_fields
,custom_fields
,
andjoin_fields
withinFlop.Schema
, as well asrepo
andquery_opts
withinuse Flop
, are now nested under theadapter_opts
keyword. The old
configuration format is still supported.
Deprecated
Flop.Schema.field_type/2
was deprecated in favor of
Flop.Schema.field_info/2
.
Removed
- Removed
Flop.Schema.apply_order_by/3
. - Removed
Flop.Schema.cursor_dynamic/3
.
Upgrade guide
While the old configuration format is still supported, you are invited to
update your application to the new structure to prepare for future versions.
To do this, place the field configuration for Flop.Schema
under
adapter_opts
:
@derive {
Flop.Schema,
filterable: [],
sortable: [],
- alias_fields: [],
- compound_fields: [],
- custom_fields: [],
- join_fields: []
+ adapter_opts: [
+ alias_fields: [],
+ compound_fields: [],
+ custom_fields: [],
+ join_fields: []
+ ]
}
Similarly for use Flop
, you can nest repo
and query_opts
under
adapter_opts
:
use Flop,
default_limit: 50,
- repo: MyApp.Repo,
- query_opts: [prefix: "some-prefix"]
+ adapter_opts: [
+ repo: MyApp.Repo,
+ query_opts: [prefix: "some-prefix"]
+ ]
0.21.0
Added
- Introduced
operators
as a new option for restricting acceptable operators
for a custom field. - Added bindings option for custom fields, allowing required named bindings to
be added viaFlop.with_named_bindings/4
. - The
ecto_type
option on join and custom fields now supports
references:{:from_schema, MySchema, :some_field}
. - The
ecto_type
option now supports a convenient syntax for adhoc enums:
{:ecto_enum, [:one, :two]}
. - Improved documentation with added type definitions:
t:Flop.Schema.option/0
,
t:Flop.Schema.join_field_option/0
,t:Flop.Schema.custom_field_option/0
,
andt:Flop.Schema.ecto_type/0
, describing options available when deriving
theFlop.Schema
protocol.
Changed
- Breaking change: Filter values are now dynamically cast based on the
field type and operator, instead of allowing any arbitrary filter value. This
change ensures that invalid filter values cause validation errors instead of
cast errors. - The options for deriving the
Flop.Schema
protocol and foruse Flop
now undergo stricter validation withNimbleOptions
. Flop.Cursor.encode/1
now explicitly sets the minor version option for
:erlang.term_to_binary/2
to2
, aligning with the new default in OTP 26.
Before, this option was not set at all.- Added a
decoded_cursor
field to theFlop
struct. This field temporarily
stores the decoded cursor between validation and querying and is
discarded when generating the meta data.
Deprecated
- The tuple syntax for defining join fields has been deprecated in favor of a
keyword list.
Fixed
- Resolved an issue where setting
replace_invalid_params
totrue
still
caused validation errors for pagination and sorting parameters due to cast
errors, instead of defaulting to valid parameters. - Fixed the type specification for
Flop.Filter.allowed_operators/1
.
Upgrade notes
The newly implemented dynamic casting of filter values could impact your code:
- Filter values failing to cast into the determined type will now yield a
validation error or result in the removal of the invalid filter if the
replace_invalid_params
option is enabled. - The
value
field of theFlop.Filter
struct now holds the cast value
instead of the original parameter value. For instance, while handling
parameters generated via an HTML form with Flop, previously all filter values
would be represented as strings in the struct. However, they may now be
integers,DateTime
structs, and so forth. Look out for this if you are
directly reading or manipulatingFlop.Filter
structs. - For join and custom fields, the type is determined with the
ecto_type
option. Previously, this option was only used for operator validation.
Ensure the correct Ecto type is set. If the option is omitted, the filter
values will continue to use their incoming format. - Manual casting of filter values in a custom filter function is no longer
required if theecto_type
option is set. - If join fields point to
Ecto.Enum
fields, previously you could simply set
ecto_type
to string. This will continue to work if the filter value is
passed as a string, but passing it as an atom will cause an error. Make sure
to correctly reference the schema field
({:from_schema, MySchema, :some_field}
) or directly pass the Enum values
({:ecto_enum, [:one, :two}
). - To enable
Flop.Phoenix
to build a query string for filter parameters, the
filter value must be convertible into a string viato_string/1
. If
ecto_type
is set to a custom Ecto type that casts values into a struct, the
String.Chars
protocol must be implemented for that struct.
Please review the newly added "Ecto type option" section in the Flop.Schema
module documentation.
Join field syntax
If you are using tuples to define join fields when deriving Flop.Schema
,
update the configuration to use keyword lists instead:
@derive {
Flop.Schema,
join_fields: [
- owner_name: {:owner, :name}
+ owner_name: [binding: :owner, field: :name]
]
}