OSDN Git Service

fix: fetch fail
[pettanr/pettanr.git] / app / models / panel_picture.rb
index 1c9ce40..3713764 100644 (file)
@@ -13,6 +13,26 @@ class PanelPicture < Peta::Element
   validates :z, :presence => true, :numericality => {:greater_than => 0}
   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
   
+  scope :with_panel, -> do
+    includes(:panel)
+  end
+  
+  scope :find_index, -> do
+    with_panel.where(Panel.arel_table[:publish].gt 0).references(:panel)
+  end
+  
+  scope :find_private, -> (operators) do 
+    with_panel.where(Panel.arel_table[:author_id].eq operators.author.id).references(:panel)
+  end
+  
+  scope :find_by_panel, -> (panel_id) do 
+    find_index.where(panel_id: panel_id).references(:panel)
+  end
+  
+  scope :find_by_author, -> (author_id) do 
+    find_index.where(Panel.arel_table[:author_id].eq author_id).references(:panel)
+  end
+  
   def self.pickup_item_name
     Picture.item_name
   end
@@ -67,7 +87,8 @@ class PanelPicture < Peta::Element
   end
   
   def filename
-    self.picture.filename + '?subdir=' + self.flip
+    q = self.flip.empty? ? '' : '?subdir=' + self.flip
+    self.picture.filename + q
   end
   
   def url