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

On 4 May 2011 09:18, Aashish K. [email protected] wrote:

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

On May 4, 9:18am, Aashish K. [email protected] wrote:

field :name

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs