# Can't find table with ActiveRecord in different thread

**URL:** <https://www.ruby-forum.com/t/cant-find-table-with-activerecord-in-different-thread/164659>\
**Category:** Ruby\
**Created:** [April 3, 2009, 6:07pm UTC](https://www.ruby-forum.com/t/cant-find-table-with-activerecord-in-different-thread/164659 "2009-04-03T18:07:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![juan\_zanos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/4da419/32.png) [@juan\_zanos](https://www.ruby-forum.com/u/juan_zanos)\
**Post date:** [April 3, 2009, 6:07pm UTC](https://www.ruby-forum.com/t/cant-find-table-with-activerecord-in-different-thread/164659/1 "2009-04-03T18:07:09Z")

</div>

Hi, I’m not sure if this is a ruby question or a rails question. If  
I create an ActiveRecord table in one thread I can’t find it in  
another thread, which I’d like to be able to do. Interestingly,  
this behavior seems to be dependent on whether all the code is in a  
single file or in separate ones, which seems odd to me.

---

<div class="post-metadata">

**Author:** ![juan\_zanos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/4da419/32.png) [@juan\_zanos](https://www.ruby-forum.com/u/juan_zanos)\
**Post date:** [April 3, 2009, 9:30pm UTC](https://www.ruby-forum.com/t/cant-find-table-with-activerecord-in-different-thread/164659/2 "2009-04-03T21:30:25Z")

</div>

On Friday 03 April 2009 11:05:21 Juan Z. wrote:

> Hi, I’m not sure if this is a ruby question or a rails question. If  
> I create an ActiveRecord table

Rails question.

> in one thread I can’t find it in  
> another thread, which I’d like to be able to do.

If you have a question about threading, that _might_ be a Ruby question.  
But  
the way Rails deals with threading is certainly a Rails question.

But while you’re here… Why do you need this? Normally, tables are  
created  
inside a migration, after which you restart the server.

---

<div class="post-metadata">

**Author:** ![juan\_zanos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/4da419/32.png) [@juan\_zanos](https://www.ruby-forum.com/u/juan_zanos)\
**Post date:** [April 3, 2009, 9:36pm UTC](https://www.ruby-forum.com/t/cant-find-table-with-activerecord-in-different-thread/164659/3 "2009-04-03T21:36:52Z")

</div>

On 3 avr. 09, at 15:29, David M. wrote:

> question. But  
> the way Rails deals with threading is certainly a Rails question.
> 
> But while you’re here… Why do you need this? Normally, tables are  
> created  
> inside a migration, after which you restart the server.

I’m not using rails, just ActiveRecord. Foo.find works in the  
thread that creates the tables. I get the message "Could not find  
table ‘foos’ " in other threads.

---

<div class="post-metadata">

**Author:** ![juan\_zanos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/4da419/32.png) [@juan\_zanos](https://www.ruby-forum.com/u/juan_zanos)\
**Post date:** [April 4, 2009, 1:23am UTC](https://www.ruby-forum.com/t/cant-find-table-with-activerecord-in-different-thread/164659/4 "2009-04-04T01:23:28Z")

</div>

On Friday 03 April 2009 14:35:50 Juan Z. wrote:

> I’m not using rails, just ActiveRecord.

Which is part of Rails. It’s one of three or four major components that  
make  
up Rails. So the Rails list is probably still worth a try.

> Foo.find works in the  
> thread that creates the tables. I get the message "Could not find  
> table ‘foos’ " in other threads.

Is it possible to create the table before loading the model in any  
thread?

Are you sure you’ve committed the transaction that had that “create  
table”  
command in it? Are you sure that’s all done before the other threads try  
the  
find?

---

<div class="post-metadata">

**Author:** ![juan\_zanos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/4da419/32.png) [@juan\_zanos](https://www.ruby-forum.com/u/juan_zanos)\
**Post date:** [April 8, 2009, 7:24am UTC](https://www.ruby-forum.com/t/cant-find-table-with-activerecord-in-different-thread/164659/5 "2009-04-08T07:24:47Z")

</div>

This is common in migrations.  
You need to tell the model that the its been modified.

> **[Update a newly added column in a migration](http://espaceblogs.blogspot.com/2007/05/update-newly-added-column-in-migration.html)**
>
> One of the very interesting features I like about Rails is migrations. It is a version control system that keeps track of all database chan...

And you should make sure that its actually created, otherwise your  
going to have a race condition.
