MySQL Forums
Forum List  »  Ruby

Help w/ pulling data from 2 tables and displaying the results
Posted by: clem c rock
Date: December 17, 2006 06:36PM

Thanks for the help.

I tried that but when I tried to spit out the table_2.info it actually produced a field from table_1.

Weird

Here's the approach I'm using now (to no avail):

The 2 tables I have are accounts and spaces. The accounts table will
have many spaces connecting the 2 tables by the foreign key user_id.

so I tried my 2 model declarations as follow:

class Account < ActiveRecord::Base
    has_many :spaces
end

class Space < ActiveRecord::Base
  belongs_to :account
end

Then I try to call the 2 tables w/ this:

@accounts = Account.find(:all, :include => :spaces )

Then I get this error:

Unknown column 'spaces.account_id' in 'on clause':

Somehow - it was getting the idea that account_id was the foreign key so
I did this:

class Account < ActiveRecord::Base
     has_many :spaces, :class_name => 'Account', :foreign_key =>
"user_id"
end

class Space < ActiveRecord::Base
    belongs_to :account, :class_name => 'Space', :foreign_key =>
"user_id"
end

and now I get this error: undefined method `loaded'

Most frustrating!

Options: ReplyQuote


Subject
Written By
Posted
Help w/ pulling data from 2 tables and displaying the results
December 17, 2006 06:36PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.