OSDN Git Service

fix: fetch fail
[pettanr/pettanr.git] / app / models / speech_balloon_template.rb
index 50db132..4660b97 100644 (file)
@@ -5,12 +5,32 @@ class SpeechBalloonTemplate < Peta::Template
   belongs_to :system_picture
   
   validates :name, :presence => true, :uniqueness => true, :length => {:maximum => 50}
-  validates :classname, :presence => true, :length => {:maximum => 50}
+  validates :module_name, :presence => true, :length => {:maximum => 50}
   validates :caption, :presence => true, :length => {:maximum => 30}
   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
   validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
   validates :settings, :presence => true
   
+  scope :find_index, -> do
+    self
+  end
+  
+  scope :find_by_original_picture, -> (original_picture_id) do 
+    find_index.where(original_picture_id: original_picture_id)
+  end
+  
+  scope :with_panels, -> do
+    includes(speech_balloons: panel)
+  end
+  
+  scope :find_by_panel, -> (panel_id) do 
+    with_panels.where(Panel.arel_table[:id].eq panel_id).references(:panel)
+  end
+  
+  scope :find_by_system_picture, -> (system_picture_id) do 
+    find_index.where(system_picture_id: system_picture_id)
+  end
+  
   def supply_default
   end
   
@@ -26,10 +46,6 @@ class SpeechBalloonTemplate < Peta::Template
     {}
   end
   
-  def self.show_json_opt
-    {}
-  end
-  
   def parsed_settings
     @parsed_settings ||= JSON.parse(self.settings)
   end