Fix `where` with a custom table
#29796

kamipo wants to merge kamipo:fix_where_with_custom_table into rails:master

We do not currently have an analysis of these two commits