All threads / Getting stuck on this query
Ask A Question

Notifications

You’re not receiving notifications from this thread.

Getting stuck on this query

Clint Baker asked in Rails

What am I missing? I have a model called Exhibit that belongs to a Request model. I have a Note model with a polymorphic relationship as the note can be about either an exhibit or a request but not both. In this case if a specific note is attached to an exhibit that happens to belong to a given Request, then how do I make a query that gets all the notes that belong to that record either directly through the polymorphic relationship tying to the request, but also the notes that are tied to that request through the exhibit model? Both exhibit and request have "has_many :notes as: :notable". I am a noob so there must be something I'm missing. I started with @notes = Note.where(noteable_type: "Exhibit").and().... just not sure where to go or even if I should be doing this differently? Thanks in advance for any help gurus!

Join the discussion

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

Join 68,099+ 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.