validates :sheet_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
+ scope :with_story, -> do
+ includes(:story)
+ end
+
+ scope :find_index, -> do
+ with_story.where(Story.arel_table[:visible].gt 0).references(:story)
+ end
+
+ scope :find_private, -> (operators) do
+ with_story.where(Story.arel_table[:author_id].eq operators.author.id).references(:story)
+ end
+
+ scope :by_story, -> (story_id) do
+ where(story_id: story_id)
+ end
+
+ scope :find_by_story, -> (story_id) do
+ find_index.by_story(story_id)
+ end
+
+ scope :find_by_sheet, -> (sheet_id) do
+ find_index.where(sheet_id: sheet_id).references(:story)
+ end
+
+ scope :find_by_author, -> (author_id) do
+ find_index.where(Story.arel_table[:author_id].eq author_id).references(:story)
+ end
+
+ scope :find_play, -> (story_id) do
+ find_by_story(story_id)
+ end
+
+ scope :find_private_play, -> (story_id, operators) do
+ find_private(operators).by_story(story_id)
+ end
+
def supply_default
self.story_id = nil
self.sheet_id = nil
self.t = nil
end
+ def overwrite operators
+ end
+
def self.public_list_where list
'stories.visible > 0'
end