# Problems with activerecord associations between tables

**URL:** <https://www.ruby-forum.com/t/problems-with-activerecord-associations-between-tables/121669>\
**Category:** Rails\
**Created:** [November 29, 2007, 8:19pm UTC](https://www.ruby-forum.com/t/problems-with-activerecord-associations-between-tables/121669 "2007-11-29T20:19:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![netbomb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@netbomb](https://www.ruby-forum.com/u/netbomb)\
**Post date:** [November 29, 2007, 8:19pm UTC](https://www.ruby-forum.com/t/problems-with-activerecord-associations-between-tables/121669/1 "2007-11-29T20:19:31Z")

</div>

Hi all,  
i’m developing an application with 40 tables that they have relations  
between them, in my  
products\_list when i render the results in my view everything worked  
fine but from one day i i get an error:  
NoMethodError in Admin/product#products\_list

Showing app/views/admin/product/products\_list.rhtml where line #35  
raised:

undefined method `re\_products\_type’ for #\<ReproductsSubtype:  
0xb731b624\>

Extracted source (around line #35):

32: \<% for item in @products %\>  
33:

  
34: \<%= item.id %\>  
35: \<%= item.re\_products\_subtype.re\_products\_type.type\_name  
%\>\</  
td\>

is strange because never happened since a month that i have started  
working on this application but if i restart apache everything is ok  
but after 5 minutes i get the same error again. I’m the only developer  
that work on this…this thing is driving me crazy.  
Any solutions or ideas please?  
thanks in advance and sorry about my english!

---

<div class="post-metadata">

**Author:** ![netbomb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@netbomb](https://www.ruby-forum.com/u/netbomb)\
**Post date:** [November 29, 2007, 10:36pm UTC](https://www.ruby-forum.com/t/problems-with-activerecord-associations-between-tables/121669/2 "2007-11-29T22:36:42Z")

</div>

On 29 Nov 2007, at 19:18, netbomb wrote:

> Hi all,  
> i’m developing an application with 40 tables that they have relations  
> between them, in my  
> products\_list when i render the results in my view everything worked  
> fine but from one day i i get an error:  
> NoMethodError in Admin/product#products\_list

Does this only happen in development mode?

Fred

---

<div class="post-metadata">

**Author:** ![netbomb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@netbomb](https://www.ruby-forum.com/u/netbomb)\
**Post date:** [November 30, 2007, 5:03am UTC](https://www.ruby-forum.com/t/problems-with-activerecord-associations-between-tables/121669/3 "2007-11-30T05:03:37Z")

</div>

Iam facing the same problem only in the development mode.  
If you find the re\_products\_subtype directly instead of getting it from  
item it may work.

---

<div class="post-metadata">

**Author:** ![netbomb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@netbomb](https://www.ruby-forum.com/u/netbomb)\
**Post date:** [November 29, 2007, 10:42pm UTC](https://www.ruby-forum.com/t/problems-with-activerecord-associations-between-tables/121669/4 "2007-11-29T22:42:16Z")

</div>

netbomb wrote:

> Hi all,

> 32: \<% for item in @products %\>  
> 33:
> 
>   
> 34: \<%= item.id %\>  
> 35: \<%= item.re\_products\_subtype.re\_products\_type.type\_name  
> %\>\</  
> td\>
> 
> is strange because never happened since a month that i have started  
> working on this application but if i restart apache everything is ok  
> but after 5 minutes i get the same error again. I’m the only developer  
> that work on this…this thing is driving me crazy.  
> Any solutions or ideas please?  
> thanks in advance and sorry about my english!
> 
> Show us app/models/re\_products\_subtype.rb and  
> app/models/re\_products\_type.rb

---

<div class="post-metadata">

**Author:** ![netbomb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@netbomb](https://www.ruby-forum.com/u/netbomb)\
**Post date:** [November 30, 2007, 9:50am UTC](https://www.ruby-forum.com/t/problems-with-activerecord-associations-between-tables/121669/5 "2007-11-30T09:50:59Z")

</div>

On 30 Nov 2007, at 08:34, netbomb wrote:

> Yes i’m in development mode, i figured out doing as showen below\>

I’ve seen some funkiness due to the autoloading stuff. major culprits  
include using require to require things that could be autoloaded

Fred

---

<div class="post-metadata">

**Author:** ![netbomb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@netbomb](https://www.ruby-forum.com/u/netbomb)\
**Post date:** [November 30, 2007, 9:34am UTC](https://www.ruby-forum.com/t/problems-with-activerecord-associations-between-tables/121669/6 "2007-11-30T09:34:33Z")

</div>

Yes i’m in development mode, i figured out doing as showen below\>

ReProductsType.find\_by\_id(item.re\_products\_subtype.re\_products\_type\_id).type\_name  
but i prefer as before…

My models:  
class ReProductsSubtype \< ActiveRecord::Base  
belongs\_to :re\_products\_type  
end

class ReProductsType \< ActiveRecord::Base  
has\_one :re\_products\_subtype  
end

I can do an explicit sql query to have better performace, but i would  
like to understand whyt this happen!  
Thanks to all

On 30 Nov, 05:03, Ayyanar Aswathaman \<rails-mailing-l…@andreas-
