# Associations stopped working

**URL:** <https://www.ruby-forum.com/t/associations-stopped-working/133301>\
**Category:** Rails\
**Created:** [March 29, 2008, 9:14pm UTC](https://www.ruby-forum.com/t/associations-stopped-working/133301 "2008-03-29T21:14:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![C.Hochstrasser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f07891/32.png) [@C.Hochstrasser](https://www.ruby-forum.com/u/C.Hochstrasser)\
**Post date:** [March 29, 2008, 9:14pm UTC](https://www.ruby-forum.com/t/associations-stopped-working/133301/1 "2008-03-29T21:14:03Z")

</div>

I have Rails 2.0.2 on Ubuntu Hardy Beta and I noticed that the  
Associations in all my Applications stopped working, that makes me  
very crazy, because I can’t develop without my associations working.

A complete reinstall of the package doesn’t solve the problem.

The Code has to be right, because it worked properly in the past, but  
yet it stopped working. I’ve tried the projects who had worked (I  
developed them already with Rails 2.0), but the associations in these  
also don’t work.

I don’t know why it’s not working, could somebody help me?

with best regards  
Christoph Hochstrasser

---

<div class="post-metadata">

**Author:** ![C.Hochstrasser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f07891/32.png) [@C.Hochstrasser](https://www.ruby-forum.com/u/C.Hochstrasser)\
**Post date:** [March 31, 2008, 11:07pm UTC](https://www.ruby-forum.com/t/associations-stopped-working/133301/2 "2008-03-31T23:07:29Z")

</div>

On 29 Mar 2008, at 20:13, C.Hochstrasser wrote:

> I have Rails 2.0.2 on Ubuntu Hardy Beta and I noticed that the  
> Associations in all my Applications stopped working, that makes me  
> very crazy, because I can’t develop without my associations working.

What do you mean by stops working? Does it still happen if you turn  
off class caching?

Fred

---

<div class="post-metadata">

**Author:** ![C.Hochstrasser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f07891/32.png) [@C.Hochstrasser](https://www.ruby-forum.com/u/C.Hochstrasser)\
**Post date:** [April 3, 2008, 11:44am UTC](https://www.ruby-forum.com/t/associations-stopped-working/133301/3 "2008-04-03T11:44:43Z")

</div>

It worked before, but yet it stopped working. When I fetch the object  
from the DB I don’t get the data from the associated Model.

Class Caching is off, I looked in my /config/environments/  
development.rb and there’s this:  
config.cache\_classes = false

Christoph

---

<div class="post-metadata">

**Author:** ![C.Hochstrasser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f07891/32.png) [@C.Hochstrasser](https://www.ruby-forum.com/u/C.Hochstrasser)\
**Post date:** [April 3, 2008, 11:55am UTC](https://www.ruby-forum.com/t/associations-stopped-working/133301/4 "2008-04-03T11:55:56Z")

</div>

On 3 Apr 2008, at 10:43, C.Hochstrasser wrote:

> It worked before, but yet it stopped working. When I fetch the object  
> from the DB I don’t get the data from the associated Model.

Does it work with class caching on? Can you see the data getting  
loaded in your logs. Can you show us any relevant code?

Fred

---

<div class="post-metadata">

**Author:** ![C.Hochstrasser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f07891/32.png) [@C.Hochstrasser](https://www.ruby-forum.com/u/C.Hochstrasser)\
**Post date:** [April 3, 2008, 12:06pm UTC](https://www.ruby-forum.com/t/associations-stopped-working/133301/5 "2008-04-03T12:06:08Z")

</div>

My Model:  
class Message \< ActiveRecord::Base  
belongs\_to :user  
validates\_presence\_of :body  
validates\_length\_of :body, :maximum=\>140  
end

When I execute find on the Message Model, I get only the data from the  
message model:  
=\> #\<Message id: 1, body: “Was gehen wir essen?”, user\_id: 1,  
created\_at: “2008-03-23 14:54:29”, updated\_at: “2008-03-23 14:54:29”\>

This is the Data that should get loaded with the Record from the  
Message Model, associated with belongs\_to:  
=\> #\<User id: 1, login: “christoph”, email:  
“removed\_email\_address@domain.invalid”, crypted\_password:  
“3dcff8ebbfe8799dbf44fd8b63dca7eef90e3db2”, salt:  
“6a10f9ea6fd2aedcf7c50e9cd00d94bf040bc7f9”, created\_at: “2008-03-22  
20:14:10”, updated\_at: “2008-03-23 16:48:23”, remember\_token: nil,  
remember\_token\_expires\_at: nil\>

From development.log:  
[4;36;1mSQL (0.041453) [0m [0;1mSET NAMES ‘utf8’ [0m  
[4;35;1mSQL (0.000303) [0m [0mSET SQL\_AUTO\_IS\_NULL=0 [0m  
[4;36;1mMessage Load (0.029746) [0m [0;1mSELECT \* FROM  
`messages` [0m  
[4;35;1mMessage Columns (0.021977) [0m [0mSHOW FIELDS FROM  
`messages` [0m  
[4;36;1mMessage Load (0.000978) [0m [0;1mSELECT \* FROM  
`messages` LIMIT 1 [0m  
[4;35;1mUser Load (0.002382) [0m [0mSELECT \* FROM `users` LIMIT  
1 [0m  
[4;36;1mUser Columns (0.002614) [0m [0;1mSHOW FIELDS FROM  
`users` [0m

Christoph

---

<div class="post-metadata">

**Author:** ![C.Hochstrasser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f07891/32.png) [@C.Hochstrasser](https://www.ruby-forum.com/u/C.Hochstrasser)\
**Post date:** [April 3, 2008, 12:51pm UTC](https://www.ruby-forum.com/t/associations-stopped-working/133301/6 "2008-04-03T12:51:16Z")

</div>

On 3 Apr 2008, at 11:05, C.Hochstrasser wrote:

> =\> #\<Message id: 1, body: “Was gehen wir essen?”, user\_id: 1,  
> created\_at: “2008-03-23 14:54:29”, updated\_at: “2008-03-23 14:54:29”\>

Are you just confused because in the rails 2.0 console it only shows  
attributes whereas before it showed everything(ie what does  
some\_message.user display?)

Fred

---

<div class="post-metadata">

**Author:** ![C.Hochstrasser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f07891/32.png) [@C.Hochstrasser](https://www.ruby-forum.com/u/C.Hochstrasser)\
**Post date:** [April 4, 2008, 8:33am UTC](https://www.ruby-forum.com/t/associations-stopped-working/133301/7 "2008-04-04T08:33:02Z")

</div>

No, as you can see the associated model data is not loaded, that means  
that I cannot access the data, in that case the name of the User from  
the User Model.

---

<div class="post-metadata">

**Author:** ![C.Hochstrasser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f07891/32.png) [@C.Hochstrasser](https://www.ruby-forum.com/u/C.Hochstrasser)\
**Post date:** [April 4, 2008, 9:34am UTC](https://www.ruby-forum.com/t/associations-stopped-working/133301/8 "2008-04-04T09:34:59Z")

</div>

On 4 Apr 2008, at 07:31, C.Hochstrasser wrote:

> No, as you can see the associated model data is not loaded, that means  
> that I cannot access the data, in that case the name of the User from  
> the User Model.

So what does happen (both on the console and in the log) if you type  
m = Message.find(1)  
m.user

Fred

---

<div class="post-metadata">

**Author:** ![C.Hochstrasser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f07891/32.png) [@C.Hochstrasser](https://www.ruby-forum.com/u/C.Hochstrasser)\
**Post date:** [April 4, 2008, 1:45pm UTC](https://www.ruby-forum.com/t/associations-stopped-working/133301/9 "2008-04-04T13:45:19Z")

</div>

I’m an idiot

Sorry, instead of calling m.user to access the data from the User  
Model, I called m.User

And now as I see it, It confused me that the rails console shows not  
all attributes as in Rails 1.x

Thank you very much Fred for your help and patience

Christoph

On Apr 4, 9:33 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
