在此示例中,我创建了一个userno profile,然后稍后profile为该用户创建一个。我尝试将build与has_one关联一起使用,但这使它崩溃了。我看到此工作的唯一方法是使用has_many。本user应该只有最多只能有一个profile。
我一直在尝试这个。我有:
class User < ActiveRecord::Base
  has_one :profile
end
class Profile < ActiveRecord::Base
  belongs_to :user
end
但是当我这样做时:
user.build_profile 
我得到错误:
ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'profiles.user_id' in 'where clause': SELECT * FROM `profiles` WHERE (`profiles`.user_id = 4)  LIMIT 1
Rails中有没有一种方法可以使0或1有关联?
                  您到底尝试了什么?可以请您发布一些代码吗?
                
                
                  
                    —
                    Ju Nogueira 2010年