rails mongoid

I have a strange problem. Suppose I have a user model with only name field. I can add a field with value by creating an instance in mongodb rails environment.

Example:

class User   include Mongoid::Document

  field :name end

Now in rails console, If you do user = User.new user[:name] = "xxxx" user[:firstname] = "yyyy" user.save

The record gets created with name and firstname fields. But i havent declared firstname field in model.

Can anyone please help me out.

Thanks, Aashish

dasDAsdas

asdasdasdas

Your keyboard is working fine. You may not see your original posting sent back to you, depending on how your mailer and the list are setup.

Colin

I have a strange problem. Suppose I have a user model with only name field. I can add a field with value by creating an instance in mongodb rails environment.

Example:

class User include Mongoid::Document

field :name end

Now in rails console, If you do user = User.new user[:name] = "xxxx" user[:firstname] = "yyyy" user.save

The record gets created with name and firstname fields. But i havent declared firstname field in model.

Can anyone please help me out.

Mongodb records don't have a fixed schema - each document can store arbitrary data. field :name just creates some convenient accessors for you (and allows you to do things like say that a certain field is required etc). See http://mongoid.org/docs/documents/dynamic.html

Fred

Thanks a lot Fred.

Can I know yr twitter id