Skip to content

Instantly share code, notes, and snippets.

@mb-dev
Last active December 11, 2015 20:48
Show Gist options
  • Save mb-dev/4657684 to your computer and use it in GitHub Desktop.
Save mb-dev/4657684 to your computer and use it in GitHub Desktop.
MongoDB Has many through
class Book
field :id
field :title
embeds_many :book_authors
# Mongoid does not offer has_many :through
def authors
book_authors.collect(&:author)
end
end
class BookAuthor
field :name
belongs_to :author
end
class Author
field :id
field :name
field :location
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment