-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
Following the documentation: http://mongoid.org/en/mongoid/docs/relations.html#embeds_one
I get the following error when I try to define an embeds_one relationship:
NameError: uninitialized constant Apikey
This is the code:
class ApiKey include Mongoid::Document field :access_token, type: String embedded_in :user before_create :generate_access_token private def generate_access_token self.access_token = SecureRandom.hex end end
class User include Mongoid::Document field :name, type: String embeds_one :apikey end
u = User.new name: 'foo' a = ApiKey.new puts u.inspect #<User _id: 54ecd47b6c6f63241d000000, name: "foo"> puts a.inspect #<ApiKey _id: 54ecdade6c6f6324fc010000, access_token: nil> u.apikey = a # Here raise the error!