[openstreetmap/openstreetmap-website] Use hashes to define where..in sql queries (PR #4136)

Andy Allan notifications at github.com
Thu Aug 3 10:05:21 UTC 2023


This is preferable to using SQL statements.

I double checked the output of the `.or()` formulation, and apart from extra table names and quoting, it's the same query.

```
> print Trace.visible.where("visibility IN ('public', 'identifiable') OR user_id = ?", u).to_sql
SELECT "gpx_files".* FROM "gpx_files" WHERE "gpx_files"."visible" = TRUE
 AND (visibility IN ('public', 'identifiable') OR user_id = 1)=> nil

> print Trace.visible.where(:visibility => %w[public identifiable]).or(Trace.visible.where(:user => u)).to_sql
SELECT "gpx_files".* FROM "gpx_files" WHERE "gpx_files"."visible" = TRUE
 AND ("gpx_files"."visibility" IN ('public', 'identifiable') OR "gpx_files"."user_id" = 1)=> nil
```
You can view, comment on, or merge this pull request online at:

  https://github.com/openstreetmap/openstreetmap-website/pull/4136

-- Commit Summary --

  * Use hashes to define where..in sql queries

-- File Changes --

    M app/controllers/application_controller.rb (2)
    M app/models/trace.rb (2)

-- Patch Links --

https://github.com/openstreetmap/openstreetmap-website/pull/4136.patch
https://github.com/openstreetmap/openstreetmap-website/pull/4136.diff

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/4136
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/4136 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20230803/9f9bbf4b/attachment-0001.htm>


More information about the rails-dev mailing list