Exception: Ohm::Model::MissingID
Overview
Raised when you try and get the id of an Ohm::Model without an id.
class Post < Ohm::Model list :comments, Comment end class Comment < Ohm::Model end ex = nil begin Post.new.id rescue Exception => e ex = e end ex.kind_of?(Ohm::Model::MissingID) # => true
This is also one of the most common errors you’ll be faced with when you’re new to Ohm coming from an ActiveRecord background, where you are used to just assigning associations even before the base model is persisted.
# following from the example above: post = Post.new ex = nil begin post.comments << Comment.new rescue Exception => e ex = e end ex.kind_of?(Ohm::Model::MissingID) # => true # Correct way: post = Post.new if post.save post.comments << Comment.create end
Instance Method Summary (collapse)
Instance Method Details
- (Object) message
1002 1003 1004 1005 |
# File 'lib/ohm.rb', line 1002 def "You tried to perform an operation that needs the model ID, " + "but it's not present." end |