Description
Expected behavior
Following this documentation https://docs.forestadmin.com/documentation/reference-guide/smart-fields#searching-sorting-and-filtering-on-a-smart-field should produce the expected results as outline in the docs.
Actual behavior
However, after upgrading to Rails 7.2.2 and ForestLiana 9.5.4 it won't work.
I believe what has happened is Rails 7.2 changed the way some of their internal APIs work and broke the way forest was doing this custom searching with the ActiveRecord::Relation::WhereClause
predicates. I guess this is the risk of trying to manipulate internal APIs to begin with, you are subject to their breaking changes.
Failure Logs
I've modified the documentation example to show logging to show that the query is not being edited as predicted.
search_fullname = lambda do |query, search|
firstname, lastname = search.split
puts 'Query before edit', query
query.where_clause.send(:predicates)[0] << " OR firstname = '#{firstname}' AND lastname = '#{lastname}')"
puts 'Query after edit', query
query
end
which produces:
Query before edit
User Load (0.9ms) SELECT "users".* FROM "users" WHERE (LOWER("users"."firstname") LIKE $1 OR LOWER("users"."lastname") LIKE $2) [[nil, "%homer simpson%"], [nil, "%homer simpson%"]]
Query after edit
SQL (1.8ms) SELECT "users"."id" AS t0_r0, "users"."firstname" AS t0_r1, "users"."lastname" AS t0_r2 WHERE (LOWER("users"."firstname") LIKE $1 OR LOWER("users"."lastname") LIKE $2 ORDER BY "users"."id" DESC LIMIT $4 OFFSET $5 [[nil, "%homer simpson%"], [nil, "%homer simpson%"], ["LIMIT", 15], ["OFFSET", 0]]
I slightly modified the output to just remove the additional column that my database actually has.
Context
- Package Version: 9.5.4
- Rails Version: 7.2.2
- Database Dialect: PostgreSQL
- Database Version: 13.18