[openstreetmap/openstreetmap-website] Lazy loading relation members (PR #6326)

mmd notifications at github.com
Mon Aug 18 19:40:06 UTC 2025


mmd-osm left a comment (openstreetmap/openstreetmap-website#6326)

I'm a bit lost how the normalisation is supposed to work - without changing anything on the db schema. I tried to use   `has_many :element_tags, :as => :relation_tags`, but PostgreSQL was complaining about some unknown columns/types.

In the meantime, the previous code is now a bit more generic, and derives associations from class names. I think that's not too bad.

```ruby
  def prefetch_member_tags(feature)
    members = feature.relation_members.filter_map(&:member)

    members.group_by(&:class).each do |klass, records|
      association = :"#{klass.name.downcase}_tags"

      ActiveRecord::Associations::Preloader.new(
        :records => records,
        :associations => association
      ).call
    end
  end
```

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

Message ID: <openstreetmap/openstreetmap-website/pull/6326/c3198171654 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20250818/df6cd1aa/attachment-0001.htm>


More information about the rails-dev mailing list