ActiveRecord with models pointing to different databases

Good morning,

My app has three basic models. They’re listed below along with their
associations

  • Project (Postgres) - Has many notes
  • Note (Postgres) - Belongs to project, user
  • User (Oracle) - Has many notes

Each note has a “validated” field (bool) and I would like to display all
unvalidated notes, by project and list who submitted the note.

Currently I have a find on Project and include notes. I then have
another find to get all Users

As I iterate through the projects, I iterate through the project notes
and inside that iteration I iterate through the users and if I get a
match for the user_id in the note to the id of the user, I print it.

I think that’s somewhat clear… I iterate through the projects with a
partial, here’s some code inside:

  1. <% for note in review_notes.notes %>
  2. <% @note = note %>
  3. <% for employee in employees %>
    
  4.   <% if employee.id.to_s == note.user_id.to_s %>
    
  5.     <print statement>
    
  6.   <% end %>
    
  7. <% end %>
  8. <% @note = nil %>
  9. <% end %>

Is there a better way to do this or am I restricted because my Users
model points to one database while the other two models point to
another? Am I able to do a sub AR find inside another find?

Output should be as follows

Project 1

  • Note one (User name)
  • Note two (User name)

Project 2

  • Note one (User name)

etc etc etc. I can pull off the Project and notes with no problem, but
having the association between the note model and user model which are
in two different databases complicates things a little bit.

Thanks!