# ActiveRecord with models pointing to different databases

**URL:** <https://www.ruby-forum.com/t/activerecord-with-models-pointing-to-different-databases/118826>\
**Category:** Rails\
**Created:** [October 31, 2007, 12:54pm UTC](https://www.ruby-forum.com/t/activerecord-with-models-pointing-to-different-databases/118826 "2007-10-31T12:54:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [October 31, 2007, 12:54pm UTC](https://www.ruby-forum.com/t/activerecord-with-models-pointing-to-different-databases/118826/1 "2007-10-31T12:54:07Z")

</div>

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!
