All threads / Polymorphic Search

Ask A Question


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

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 53,130+ 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.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2021 GoRails, LLC. All rights reserved.