Method: Sohm::Model.list
- Defined in:
- lib/sohm.rb
.list(name, model) ⇒ Object
Declare an Sohm::List with the given name.
Example:
class Comment < Sohm::Model
end
class Post < Sohm::Model
list :comments, :Comment
end
p = Post.create
p.comments.push(Comment.create)
p.comments.unshift(Comment.create)
p.comments.size == 2
# => true
Note: You can’t use the list until you save the model. If you try to do it, you’ll receive an Sohm::MissingID error.
687 688 689 690 691 692 693 694 695 |
# File 'lib/sohm.rb', line 687 def self.list(name, model) track(name) define_method name do model = Utils.const(self.class, model) Sohm::List.new(key[name], model.key, model) end end |