Read error: #<NameError: uninitialized constant LinkedInModels::Person>

9 views
Skip to first unread message

Mark Nijhof

unread,
Sep 7, 2010, 11:21:17 AM9/7/10
to MongoMapper
Hi,

I am converting my project from Mongoid to MongoMapper and I am
running into some weird issues where I am getting the following error
"Read error: #<NameError: uninitialized constant
LinkedInModels::Person>" from my tests. And it is pointing to the
following line: "person = LinkedInModels::Person.get_by_id user_id"

Now I can just return nil straight from that method and it results in
the same result. So I would say it is not that method, but more how it
is called.

I have seen other posts with a similar error and I have tried the
solution there as well by using mongo_ext 1.18.2 but that didn't help.
I think the latest not is 1.19.3 and that fails as well.

The weird thing is that in many other places I don't see these errors,
just with this specific class:


module LinkedInModels
class Person
include MongoMapper::Document
plugin MongoMapper::Plugins::Timestamps
set_collection_name 'people'

key :first_name
key :last_name
key :friendly_name
key :openid_name
key :email_address
key :address
key :postal_code
key :city
key :beta_user

key :open_id_ids, Array
key :open_id_names, Array
key :email_addresses, Array
key :photo_urls, Array

many :OpenidProviders, :class_name =>
'LinkedInModels::OpenidProvider'

class << self
def get_user_name
friendly_name.nil? || friendly_name == "" ? openid_name :
friendly_name
end

def get_by_id person_id
return LinkedInModels::Person.all('_id' => person_id).first
end

def get_provider_by_id provider_name, person_id
person = get_by_id person_id
if person.nil?
return nil
end

person.OpenidProviders.select(|item| item.provider_name ==
provider_name).first
end
end

end
end

One side note, I am using multiple models with the same name, only
different behavior and perhaps state (meaning what state I need, not
the actual state). That is why I change the collection name.

-Mark

Jamie Orchard-Hays

unread,
Sep 7, 2010, 11:38:13 AM9/7/10
to mongo...@googlegroups.com
I'd just get rid of that method. It's redundant:

def get_by_id person_id
return LinkedInModels::Person.all('_id' => person_id).first
end

Is the same as just calling

Person.find(the_id)

Also, if you want the first of something:

Person.first(:foo => value)

Finally, gem uninstall mongo_ext. It was renamed bson_ext a few months back. You should have mongo, bson, bson_ext and mongo_mapper gems.

Jamie

Docs are sparse, but if you look at the tests, you'll find what you need.

Jamie

> --
> You received this message because you are subscribed to the Google
> Groups "MongoMapper" group.
> For more options, visit this group at
> http://groups.google.com/group/mongomapper?hl=en?hl=en

Mark Nijhof

unread,
Sep 7, 2010, 2:23:36 PM9/7/10
to mongo...@googlegroups.com
Hi Jamie,

Thanks for several tips on retrieving, much nicer.

I am not sure what it was exactly, but your suggestions alone where
not enough, but I managed to get it fixed. Unfortunately I don't know
how :(

-Mark

--
Mark Nijhof
m: 0047 95 00 99 37
e:  mark....@cre8ivethought.com
b:  cre8ivethought.com/blog/index

"Walking on water and developing software from a specification are
easy if both are frozen."

-- Edward V Berard

vierund...@googlemail.com

unread,
Sep 9, 2010, 9:49:26 AM9/9/10
to MongoMapper
> I am converting my project from Mongoid to MongoMapper

Just curiosity: Why are you converting from mongoid to mongomapper?
Whenever I'm lost with the sparse documentation of mm, some minor
annoyances and the lack of ActiveModel-Support I'm playing with the
idea of moving to mongoid. Probably this is only a case of the grass
being greener everywhere where I am not, so I'm curious what brought
you to mm?!


PS: And of course, MM also has its moments of greatness...


Fabrizio Regini

unread,
Sep 9, 2010, 9:59:09 AM9/9/10
to mongo...@googlegroups.com
I'd like to hear it too. I'm using MM on several projects an it's doing well for me, but I'm interested in opinions on MongoID.

Reply all
Reply to author
Forward
0 new messages