| Class | Ohm::List |
| In: |
lib/ohm.rb
|
| Parent: | Object |
| key | [R] | |
| model | [R] | |
| namespace | [R] |
Delete a model from the list.
Note: If your list contains the model multiple times, this method will delete all instances of that model in one go.
Example:
class Comment < Ohm::Model
end
class Post < Ohm::Model
list :comments, :Comment
end
p = Post.create
c = Comment.create
p.comments.push(c)
p.comments.push(c)
p.comments.delete(c)
p.comments.size == 0
# => true
Returns an array with all the ID‘s of the list.
class Comment < Ohm::Model
end
class Post < Ohm::Model
list :comments, :Comment
end
post = Post.create
post.comments.push(Comment.create)
post.comments.push(Comment.create)
post.comments.push(Comment.create)
post.comments.map(&:id)
# => ["1", "2", "3"]
post.comments.ids
# => ["1", "2", "3"]
Returns an array of elements from the list using LRANGE. range receives 2 integers, start and stop
Example:
class Comment < Ohm::Model
end
class Post < Ohm::Model
list :comments, :Comment
end
c1 = Comment.create
c2 = Comment.create
c3 = Comment.create
post = Post.create
post.comments.push(c1)
post.comments.push(c2)
post.comments.push(c3)
[c1, c2] == post.comments.range(0, 1)
# => true