Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongoid - Overwriting existing field warning

I'm just starting with mongodb. I have a rails 4.0 app using mongodb via mongoid (4.0.0) There is a Company model and a User model. So User belongs_to :company and Company has_many :users

When I start the console and I do Company.first I get a company I created. When I do Company.first.users the first time I get:

WARN -- : Overwriting existing field for all the fields.

And then the company users as expected.

When I do it a second time then there are no warnings and just the company users.

Why is that? Is there anything wrong going on? I have the app in Heroku and the same happens there.

Thanks.

update 1

This is the model

class Company
    include Mongoid::Document
    include Mongoid::Timestamps

    field :name
    field :token

    has_many :users
    has_many :feedbacks
    has_many :main_categories
    has_many :departments

end

Update 2

Actually these warning only occur with the User model

User.all
W, [2013-10-05T21:30:34.522867 #23442]  WARN -- : Overwriting existing field email in class User.
W, [2013-10-05T21:30:34.523418 #23442]  WARN -- : Overwriting existing field crypted_password in class User.
W, [2013-10-05T21:30:34.523662 #23442]  WARN -- : Overwriting existing field salt in class User.
W, [2013-10-05T21:30:34.523888 #23442]  WARN -- : Overwriting existing field remember_me_token in class User.
W, [2013-10-05T21:30:34.524129 #23442]  WARN -- : Overwriting existing field remember_me_token_expires_at in class User.
W, [2013-10-05T21:30:34.524367 #23442]  WARN -- : Overwriting existing field reset_password_token in class User.
W, [2013-10-05T21:30:34.524595 #23442]  WARN -- : Overwriting existing field reset_password_token_expires_at in class User.
W, [2013-10-05T21:30:34.524834 #23442]  WARN -- : Overwriting existing field reset_password_email_sent_at in class User.
W, [2013-10-05T21:30:34.525070 #23442]  WARN -- : Overwriting existing field failed_logins_count in class User.
W, [2013-10-05T21:30:34.525319 #23442]  WARN -- : Overwriting existing field last_login_at in class User.
W, [2013-10-05T21:30:34.525546 #23442]  WARN -- : Overwriting existing field last_logout_at in class User.
W, [2013-10-05T21:30:34.525774 #23442]  WARN -- : Overwriting existing field last_activity_at in class User.
 => #<Mongoid::Criteria
  selector: {}
  options:  {}
  class:    User
  embedded: false>

1.9.3p327 :003 > Company.all
 => #<Mongoid::Criteria
  selector: {}
  options:  {}
  class:    Company
  embedded: false>

Update 3

This is related to Sorcery so I'll check with them.

like image 655
Pod Avatar asked Oct 15 '25 04:10

Pod


1 Answers

Is Company model extending another model? This warning is there to warn people about fields that are being overwriting in a child class. Also if you know that you are overwriting a field, you can pass a option overwrite: true , so the warning wont show up.

like image 56
Arthur Neves Avatar answered Oct 17 '25 17:10

Arthur Neves



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!