validates :scroll_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :panel_id, :presence => true, :numericality => true, :existence => {:both => false}
- validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
+ scope :with_scroll, -> do
+ includes(:scroll)
+ end
+
+ scope :find_index, -> do
+ with_scroll.where(Scroll.arel_table[:visible].gt 0).references(:scroll)
+ end
+
+ scope :find_private, -> (operators) do
+ with_scroll.where(Scroll.arel_table[:author_id].eq operators.author.id).references(:scroll)
+ end
+
+ scope :by_scroll, -> (scroll_id) do
+ where(scroll_id: scroll_id)
+ end
+
+ scope :find_by_scroll, -> (scroll_id) do
+ find_index.by_scroll(scroll_id).references(:scroll)
+ end
+
+ scope :find_by_panel, -> (panel_id) do
+ find_index.where(panel_id: panel_id).references(:scroll)
+ end
+
+ scope :find_by_author, -> (author_id) do
+ find_index.where(Scroll.arel_table[:author_id].eq author_id).references(:scroll)
+ end
+
+ scope :find_play, -> (scroll_id) do
+ find_by_scroll(scroll_id)
+ end
+
+ scope :find_private_play, -> (scroll_id, operators) do
+ find_private(operators).by_scroll(scroll_id)
+ end
+
def supply_default
self.scroll_id = nil
self.panel_id = nil
end
def overwrite operators
- return false unless operators.author
- self.author_id = operators.author.id
- end
-
- def self.public_list_order
- 'scroll_panels.updated_at desc'
end
- def self.public_list_where
+ def self.public_list_where list
'scrolls.visible > 0'
end
def self.by_author_list_includes
- {
- :scroll => {
- :author => {}
- }
- }
+ [:scroll => :author]
end
def self.show_opt
{:include => {
- :author => {},
:scroll => {
:author => {}
},
- :panel => {
- :author => {},
- :panel_pictures => {:picture => {:artist => {}, :license => {}}},
- :speech_balloons =>{:balloon => {}, :speech => {}}
- }
}}
end