Thanks for getting back to me on this. I've been reading about this
aproach and I've tried to implemented it in my project.
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
Then I try to call the 2 tables w/ this:
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!
Bookmarks