Created
March 21, 2011 01:28
-
-
Save MarkMenard/878875 to your computer and use it in GitHub Desktop.
This file contains 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
class Document | |
include Mongoid::Document | |
field :query_subject, :type => String | |
field :content, :type => String | |
class << self | |
def find_current (query_subject) | |
self.where(:query_subject => query_subject).order_by(:created_at.desc).first | |
end | |
end | |
end | |
# Why would this throws the following exception? | |
jruby-1.6.0 :025 > Document.find_current('alkjdf') | |
Mongoid::Errors::InvalidCollection: Access to the collection for Document is not allowed since it is an embedded document, please access a collection from the root document. | |
from /Users/mark/.rvm/gems/jruby-1.6.0@we_build_pages/gems/mongoid-2.0.0.rc.7/lib/mongoid/collections.rb:21:in `collection' | |
from /Users/mark/.rvm/gems/jruby-1.6.0@we_build_pages/gems/mongoid-2.0.0.rc.7/lib/mongoid/contexts/mongo.rb:255:in `one' | |
from org/jruby/RubyKernel.java:2038:in `send' | |
from /Users/mark/.rvm/gems/jruby-1.6.0@we_build_pages/gems/mongoid-2.0.0.rc.7/lib/mongoid/criteria.rb:36:in `first' | |
from /Users/mark/projects/we_build_pages/app/models/document.rb:9:in `find_current' | |
from (irb):25:in `evaluate' | |
from org/jruby/RubyKernel.java:1087:in `eval' | |
from /Users/mark/.rvm/rubies/jruby-1.6.0/lib/ruby/1.8/irb.rb:158:in `eval_input' | |
from /Users/mark/.rvm/rubies/jruby-1.6.0/lib/ruby/1.8/irb.rb:271:in `signal_status' | |
from /Users/mark/.rvm/rubies/jruby-1.6.0/lib/ruby/1.8/irb.rb:155:in `eval_input' | |
from org/jruby/RubyKernel.java:1417:in `loop' | |
from org/jruby/RubyKernel.java:1190:in `catch' | |
from /Users/mark/.rvm/rubies/jruby-1.6.0/lib/ruby/1.8/irb.rb:154:in `eval_input' | |
from /Users/mark/.rvm/rubies/jruby-1.6.0/lib/ruby/1.8/irb.rb:71:in `start' | |
from org/jruby/RubyKernel.java:1190:in `catch' | |
from /Users/mark/.rvm/rubies/jruby-1.6.0/lib/ruby/1.8/irb.rb:70:in `start' | |
from /Users/mark/.rvm/gems/jruby-1.6.0@we_build_pages/gems/railties-3.0.3/lib/rails/commands/console.rb:44:in `start' | |
from /Users/mark/.rvm/gems/jruby-1.6.0@we_build_pages/gems/railties-3.0.3/lib/rails/commands/console.rb:8:in `start' | |
from /Users/mark/.rvm/gems/jruby-1.6.0@we_build_pages/gems/railties-3.0.3/lib/rails/commands.rb:23:in `(root)' | |
from org/jruby/RubyKernel.java:1037:in `require' | |
from script/rails:6:in `(root)'jruby-1.6.0 :026 > | |
jruby-1.6.0 :035 > Document.new.embedded_many? | |
=> nil | |
jruby-1.6.0 :036 > Document.new.embedded_one? | |
=> nil | |
jruby-1.6.0 :037 > Document.new.embedded? | |
=> true | |
jruby-1.6.0 :038 > | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment