Hello,
I'm brand new to ruby and I'm having trouble pulling data from one
table (table_1), looping through the results and pulling data from
another table (table_2) and displaying the results of table_2 in one
field.
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:
Then I try to call the 2 tables w/ this:
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:
and now I get this error: undefined method `loaded'
Most frustrating!
I'm brand new to ruby and I'm having trouble pulling data from one
table (table_1), looping through the results and pulling data from
another table (table_2) and displaying the results of table_2 in one
field.
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:
Code:
class Account < ActiveRecord::Base has_many :spaces end class Space < ActiveRecord::Base belongs_to :account end
Code:
@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:
Code:
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!