2017-07-09 13:41:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2007-10-27 14:51:32 -04:00
|
|
|
class Book < ActiveRecord::Base
|
2017-05-02 15:37:06 -04:00
|
|
|
belongs_to :author
|
2010-09-26 08:17:18 -04:00
|
|
|
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :citations, foreign_key: "book1_id"
|
2013-11-02 15:01:31 -04:00
|
|
|
has_many :references, -> { distinct }, through: :citations, source: :reference_of
|
2010-07-27 16:57:27 -04:00
|
|
|
|
|
|
|
has_many :subscriptions
|
2013-11-02 15:01:31 -04:00
|
|
|
has_many :subscribers, through: :subscriptions
|
2013-11-02 16:08:36 -04:00
|
|
|
|
|
|
|
enum status: [:proposed, :written, :published]
|
2020-05-13 06:58:12 -04:00
|
|
|
enum last_read: { unread: 0, reading: 2, read: 3, forgotten: nil }
|
2014-01-20 20:10:48 -05:00
|
|
|
enum nullable_status: [:single, :married]
|
2015-07-23 08:27:09 -04:00
|
|
|
enum language: [:english, :spanish, :french], _prefix: :in
|
|
|
|
enum author_visibility: [:visible, :invisible], _prefix: true
|
|
|
|
enum illustrator_visibility: [:visible, :invisible], _prefix: true
|
|
|
|
enum font_size: [:small, :medium, :large], _prefix: :with, _suffix: true
|
2016-09-11 02:29:00 -04:00
|
|
|
enum difficulty: [:easy, :medium, :hard], _suffix: :to_read
|
2016-08-06 12:26:20 -04:00
|
|
|
enum cover: { hard: "hard", soft: "soft" }
|
2019-12-24 02:11:07 -05:00
|
|
|
enum boolean_status: { enabled: true, disabled: false }
|
2013-11-04 13:36:22 -05:00
|
|
|
|
|
|
|
def published!
|
|
|
|
super
|
|
|
|
"do publish work..."
|
|
|
|
end
|
2007-10-27 14:51:32 -04:00
|
|
|
end
|
2019-05-08 08:41:43 -04:00
|
|
|
|
|
|
|
class PublishedBook < ActiveRecord::Base
|
|
|
|
self.table_name = "books"
|
|
|
|
|
|
|
|
validates_uniqueness_of :isbn
|
|
|
|
end
|