validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :publish, :presence => true, :numericality => true
+ scope :find_index, -> do
+ where(arel_table[:publish].gt 0)
+ end
+
+ scope :find_private, -> (operators) do
+ where(author_id: operators.author.id)
+ end
+
+ scope :find_by_author, -> (author_id) do
+ find_index.where(author_id: author_id)
+ end
+
+ scope :with_scrolls, -> do
+ includes(scroll_panels: :scroll)
+ end
+
+ scope :find_by_scroll, -> (scroll_id) do
+ with_scrolls.find_index.where(Scroll.arel_table[:id].eq scroll_id).references(:scroll)
+ end
+
+ scope :with_sheets, -> do
+ includes(sheet_panels: :sheet)
+ end
+
+ scope :find_by_sheet, -> (sheet_id) do
+ with_sheets.find_index.where(Sheet.arel_table[:id].eq sheet_id).references(:sheet)
+ end
+
+ scope :with_speech_balloons, -> do
+ includes(:speech_balloons)
+ end
+
+ scope :find_by_speech_balloon_template, -> (speech_balloon_template_id) do
+ with_speech_balloons.find_index.where(SpeechBalloon.arel_table[:speech_balloon_template_id].eq speech_balloon_template_id).references(:speech_balloon)
+ end
+
def supply_default
self.border = 2
self.publish = 0