nviennot/nobrainer — pull request #15 by alex-klepa (2013-09-23 16:53:51+00:00)
Title: Many-to-many relation support

Example usage:

```ruby
class Link
include NoBrainer::Document
field :url
belongs_to :comment
end

class Comment
include NoBrainer::Document

field :body
has_many :posts, through: 'comments_posts'

has_many :links
end

class Post
include NoBrainer::Document

field :title
field :content
field :author

has_many :comments, through: 'comments_posts'
end

class CommentsPost
include NoBrainer::Document

belongs_to :comment
belongs_to :post

field :category
end

p = Post.create(title: 'Test Article', content: 'Text Text Text Text Text', author: 'Alex')
p.comments(category: 'Art').create(body: 'Text Text Text Text Text')
p.comments(category: 'Internet').create(body: 'Text Text Text Text Text')

# Print comments from 'Art' category
puts p.comments(category: 'Art').to_a.inspect

# Print comments from 'Internet' category
puts p.comments(category: 'Internet').to_a.inspect

# Print all comments
puts p.comments.to_a.inspect
```