Two belongs_to relationships in one model?

Hi, Class_* do not represent valid model names in Rails in the default case.

In any case, I would recommend reading AWDwR 3rd Edition if you’re new to

Rails.

Good luck,

-Conrad

Hi, in the original e-mail you said that you were receiving an error message in regards to

SQLite3. OK, if you have classa and classb, you should have created the following

databases:

classas

classbs

If this isn’t the case, you’ll need to create the databases.

-Conrad

Conrad Taylor wrote:

Hi, in the original e-mail you said that you were receiving an error message in regards to SQLite3. OK, if you have classa and classb, you should have created the following
databases:

classas
classbs

If this isn't the case, you'll need to create the databases.

I am sure you meant tables, not databases ... :smiley:

Conrad Taylor wrote:

Hi, in the original e-mail you said that you were receiving an error

message in regards to

SQLite3. OK, if you have classa and classb, you should have created the

following

databases:

classas

classbs

If this isn’t the case, you’ll need to create the databases.

I am sure you meant tables, not databases … :smiley:

Martin, thanks for correcting me.

Hi, please explain what you’re trying to do. It’s rare that you’ll have two

belongs_to declaration. However, I’m sure this may be possible in some

use cases.

-Conrad

I'm trying to append files to either a "post" or a "message". Files
belong to either a post or a message.

So post-model:

has_many :files

message-model:

has_many :files

file-model:

belongs_to :post
belongs_to :message

I'm trying to add the file-functionality to the existing
post/message-structure.

You might want to have a look at polymorphic associations, or you
could just have two separate belongs_to, one of which will be null for
any given file.

Fred

What you want is polymorphic joins. Look it up in google.

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/