Clint Baker

Joined

410 Experience
3 Lessons Completed
0 Questions Solved

Activity

Posted in Getting stuck on this query

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!

Posted in How do I return a scope that I think includes a select?

Thanks Amie! That worked!! So great to be able to get help to figure out some of the problems that crop up and where you have a mental block. So much saner than toiling with it for hours!

Clint

Posted in How do I return a scope that I think includes a select?

Hello,

I have a Model called Orgchart and it contains a position. In the users table there is an orgchart_id for each user. I have a select box on a form and I want to fill it with all the positions from orgcharts table that are NOT connected to a user in the users table. So essentally I feel like this should be a nil result from a nested select somehow but I'm drawing a blank. Probably the scope could be called available_positions as that would make more sense. Essentally return all of the Orgchart records where position is unused.

scope :empty_positions, -> {  Not sure how to construct this! }

How do I do this?

Clint