Skip to content

Instantly share code, notes, and snippets.

Created November 4, 2014 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/087e6c81ef5f355a160d to your computer and use it in GitHub Desktop.
Save anonymous/087e6c81ef5f355a160d to your computer and use it in GitHub Desktop.
class Book
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Slug
# ----------------------------------
# Book fields
# ----------------------------------
field :internal_id, type: String
field :just_ported, type: Boolean, default: false
field :cover_ported, type: Boolean, default: false
field :cover_checked, type: Boolean, default: false
field :prominent, type: Boolean, default: false
field :editorial_data_checked, type: Boolean, default: false
field :entities_checked, type: Boolean, default: false
field :id_mbm, type: String
field :format, type: String
field :digital_format, type: String
field :isbn, type: String
field :isbn_paper, type: String
field :isbn_ebook, type: String
field :isbn_other1, type: String
field :isbn_other2, type: String
field :isbn_origin, type: String
field :num_pages, type: String
field :title, type: String
field :subtitle, type: String
field :curator, type: String
field :translator, type: String
field :illustrator, type: String
field :editor, type: String
field :mark, type: String
field :year_publication, type: String
field :age_rating, type: String
field :abstract_long, type: String
field :abstract_short, type: String
field :bisac_1, type: String
field :bisac_2, type: String
field :bisac_3, type: String
field :bisac_4, type: String
field :bisac_5, type: String
field :bisac_6, type: String
field :bisac_7, type: String
field :bisac_8, type: String
field :bisac_9, type: String
field :bisac_10, type: String
field :typology, type: String
field :book_website, type: String
field :book_facebook, type: String
field :book_youtube, type: String
field :book_twitter, type: String
field :book_other, type: String
field :ecommerce_url, type: String
field :launch_number, type: String
field :miv_date, type: String
field :in_catalog, type: String
field :related_calculated_on, type: DateTime
field :has_semantic, type: Boolean, default: false
field :has_cover, type: Boolean, default: false
field :comments_count, type: Integer, default: 0
field :cached_entities, type: Array
# ----------------------------------
# Indexes
# ----------------------------------
index({internal_id: 1}, unique: true, name: "internal_id_index", background: true)
index({likes_count: 1}, background: true)
index({comments_count: 1}, background: true)
index({has_semantic: 1}, background: true)
index({has_cover: 1}, background: true)
index({editorial_data_checked: 1}, background: true)
index({entities_checked: 1}, background: true)
index({has_cover: 1, has_semantic: 1}, background: true)
# ----------------------------------
# Embedded relations
# ----------------------------------
embeds_many :related_books
embeds_many :relevant_entities
# ----------------------------------
# External relations
# ----------------------------------
belongs_to :category, index: true
belongs_to :editor, index: true
has_many :related_phrases
has_many :correlations # N-N relation to entities
has_many :comments, order: 'created_at DESC'
has_many :actions
has_and_belongs_to_many :authors, index: true
has_and_belongs_to_many :users
slug :title
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment