OSDN Git Service

merge
[pettanr/pettanr.git] / app / models / comic_story.rb
index 59b8096..7f773d8 100644 (file)
@@ -8,6 +8,42 @@ class ComicStory < Peta::Leaf
   validates :story_id, :presence => true, :numericality => true, :existence => {:both => false}
   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
   
+  scope :with_comic, -> do
+    includes(:comic)
+  end
+  
+  scope :find_index, -> do
+    with_comic.where(Comic.arel_table[:visible].gt 0).references(:comic)
+  end
+  
+  scope :find_private, -> (operators) do 
+    with_comic.where(Comic.arel_table[:author_id].eq operators.author.id).references(:comic)
+  end
+  
+  scope :by_comic, -> (comic_id) do 
+    where(comic_id: comic_id)
+  end
+  
+  scope :find_by_comic, -> (comic_id) do 
+    find_index.by_comic(comic_id)
+  end
+  
+  scope :find_by_story, -> (story_id) do 
+    find_index.where(story_id: story_id).references(:comic)
+  end
+  
+  scope :find_by_author, -> (author_id) do 
+    find_index.where(Comic.arel_table[:author_id].eq author_id).references(:comic)
+  end
+  
+  scope :find_play, -> (comic_id) do 
+    find_by_comic(comic_id)
+  end
+  
+  scope :find_private_play, -> (comic_id, operators) do 
+   find_private(operators).by_comic(comic_id)
+  end
+  
   def supply_default
     self.comic_id = nil
     self.story_id = nil
@@ -15,7 +51,6 @@ class ComicStory < Peta::Leaf
   end
   
   def overwrite operators
-    return false unless operators.author
   end
   
   def disp_t