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:
- <% for note in review_notes.notes %>
- <% @note = note %>
-
<% for employee in employees %>
-
<% if employee.id.to_s == note.user_id.to_s %>
-
<print statement>
-
<% end %>
- <% end %>
- <% @note = nil %>
- <% 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!