All threads / Polymorphic Search
Ask A Question

Notifications

You’re not receiving notifications from this thread.

Polymorphic Search

Dan Tappin asked in Databases

I have a basic model structure like this:

class History < ActiveRecord::Base
  belongs_to :historical, polymorphic: true, touch: true
end

with several related models:

has_many :history, :as => :historical, :dependent => :destroy

It seem to me that there is no easy way to search the History model AND the related models. For example each related model has a name and notes field. Can I do some sort of crazy multiple join and use conditions on the join?

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 66,257+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2022 GoRails, LLC. All rights reserved.