-
I have an Ecto.Schema that contains a json field within(payment). That field is and embedded_schema that contains another another embedded_schema as they are not persisted in different tables I was trying to use Flop for filtering withing nested schemas, but from what i understood we would need a query that joins and because they are only persisted in memory i don't think this will work. So my question is: is there a way to filter using Flop inside json fields? Follows an extract of my code for "visualization"
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can configure a custom field and use a fragment with one of the Postgres JSON operators. Alternatively, you can add a lateral join in which you select the value using the same fragment and operator as you would use in the custom field, give the binding an name, and configure a join field. The advantage of this option is that Flop can apply any operator here, while with the custom field, you have to implement each operator you want to support. The Postgres query optimizer should be able to optimize the lateral join away. Check the query plan to confirm. |
Beta Was this translation helpful? Give feedback.
You can configure a custom field and use a fragment with one of the Postgres JSON operators.
Alternatively, you can add a lateral join in which you select the value using the same fragment and operator as you would use in the custom field, give the binding an name, and configure a join field. The advantage of this option is that Flop can apply any operator here, while with the custom field, you have to implement each operator you want to support. The Postgres query optimizer should be able to optimize the lateral join away. Check the query plan to confirm.