-
-
Save ilpoldo/800143 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
# Create an italian word and add a definition to it | |
>> w = Word.create(:word => 'cestino', :language => :it) | |
#<Word _id: 4d41abc38b8e6b3001000002, word: "cestino", language: :it, origin: nil, pronunciation: nil> | |
>> w.definitions.create :kind => :noun, :text => 'un posto dove buttare le cose' | |
#<Definition _id: 4d42a9238b8e6b5fa2000003, kind: :noun, text: "un posto dove buttare le cose"> | |
# Add a translation (a word in another language) to the definition | |
>> w.definitions.first.translations.create(:word => 'recycling bin', :language => :en) | |
NoMethodError: undefined method `first' for #<Definition:0x10668c020> | |
from /Users/Le/.rvm/gems/ree-1.8.7-2010.01/gems/mongoid-2.0.0.rc.6/lib/mongoid/attributes.rb:75:in `method_missing' | |
from /Users/Le/.rvm/gems/ree-1.8.7-2010.01/gems/mongoid-2.0.0.rc.6/lib/mongoid/relations/builders/embedded/many.rb:21:in `build' | |
from /Users/Le/.rvm/gems/ree-1.8.7-2010.01/gems/mongoid-2.0.0.rc.6/lib/mongoid/relations/accessors.rb:59:in `create_relation' | |
from /Users/Le/.rvm/gems/ree-1.8.7-2010.01/gems/mongoid-2.0.0.rc.6/lib/mongoid/relations/accessors.rb:26:in `build' | |
from /Users/Le/.rvm/gems/ree-1.8.7-2010.01/gems/mongoid-2.0.0.rc.6/lib/mongoid/relations/accessors.rb:149:in `definitions=' | |
from /Users/Le/.rvm/gems/ree-1.8.7-2010.01/gems/mongoid-2.0.0.rc.6/lib/mongoid/extensions/object/yoda.rb:22:in `send' | |
from /Users/Le/.rvm/gems/ree-1.8.7-2010.01/gems/mongoid-2.0.0.rc.6/lib/mongoid/extensions/object/yoda.rb:22:in `do_or_do_not' | |
from /Users/Le/.rvm/gems/ree-1.8.7-2010.01/gems/mongoid-2.0.0.rc.6/lib/mongoid/relations/bindings/referenced/many.rb:46:in `bind_one' | |
from /Users/Le/.rvm/gems/ree-1.8.7-2010.01/gems/mongoid-2.0.0.rc.6/lib/mongoid/relations/referenced/many.rb:273:in `append' | |
from /Users/Le/.rvm/gems/ree-1.8.7-2010.01/gems/mongoid-2.0.0.rc.6/lib/mongoid/relations/many.rb:44:in `build' | |
from /Users/Le/.rvm/gems/ree-1.8.7-2010.01/gems/mongoid-2.0.0.rc.6/lib/mongoid/relations/many.rb:43:in `tap' | |
from /Users/Le/.rvm/gems/ree-1.8.7-2010.01/gems/mongoid-2.0.0.rc.6/lib/mongoid/relations/many.rb:43:in `build' | |
from /Users/Le/.rvm/gems/ree-1.8.7-2010.01/gems/mongoid-2.0.0.rc.6/lib/mongoid/relations/referenced/many.rb:70:in `create' | |
from (irb):39 | |
from :0 | |
>> w.definitions.first.translations | |
[ | |
[0] #<Word _id: 4d42a9a48b8e6b5fa2000004, word: nil, language: nil, origin: nil, pronunciation: nil> | |
] |
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 Word | |
include Mongoid::Document | |
field :word | |
field :pronunciation | |
field :language | |
field :origin | |
embeds_many :definitions | |
accepts_nested_attributes_for :definition | |
end | |
class Definition | |
include Mongoid::Document | |
field :kind | |
field :text | |
embedded_in :word | |
references_many :synonims, :class_name => 'Word' | |
references_many :translations, :class_name => 'Word' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment