Created
June 16, 2010 19:03
-
-
Save akeem/441119 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__)) | |
require 'mongo_mapper' | |
require 'pp' | |
class NedFlanders | |
def initialize | |
MongoMapper.database = 'testing' | |
end | |
end | |
#x = NedFlanders.new #if you specify the database prior to scope method declaration things seem to work well. | |
class User | |
include MongoMapper::Document | |
# plain old vanilla scopes with fancy queries | |
scope :johns, where(:name => 'John') | |
key :name, String | |
key :tags, Array | |
end | |
x = NedFlanders.new | |
User.collection.remove # empties collection | |
User.create(:name => 'John', :tags => %w[ruby mongo]) | |
# simple scopes | |
pp User.johns.first |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment