Bu örnekte, userno ile bir oluşturuyorum profile, daha sonra profilebu kullanıcı için bir oluştur . Bir has_onedernek ile build kullanmayı denedim ama bu patladı. Bu çalışmayı görmenin tek yolu kullanmak has_many. userSadece en birisinde olması gerekiyordu profile.
Bunu deniyorum. Sahibim:
class User < ActiveRecord::Base
has_one :profile
end
class Profile < ActiveRecord::Base
belongs_to :user
end
Ama yaptığım zaman:
user.build_profile
Hatayı alıyorum:
ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'profiles.user_id' in 'where clause': SELECT * FROM `profiles` WHERE (`profiles`.user_id = 4) LIMIT 1
Raylarda 0 veya 1 ilişki kurmanın bir yolu var mı?