Associations stopped working

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

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

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

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

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:
[email protected]”, 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

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

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.

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

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. [email protected]