post_archive.rb: readd associations.
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
class PostArchive < ActiveRecord::Base
|
class PostArchive < ActiveRecord::Base
|
||||||
extend Memoist
|
extend Memoist
|
||||||
|
|
||||||
|
belongs_to :post
|
||||||
|
belongs_to :updater, class_name: "User"
|
||||||
|
|
||||||
def self.enabled?
|
def self.enabled?
|
||||||
Danbooru.config.aws_sqs_archives_url.present?
|
Danbooru.config.aws_sqs_archives_url.present?
|
||||||
end
|
end
|
||||||
@@ -92,18 +95,10 @@ class PostArchive < ActiveRecord::Base
|
|||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
def post
|
|
||||||
Post.where(id: post_id).first
|
|
||||||
end
|
|
||||||
|
|
||||||
def previous
|
def previous
|
||||||
PostArchive.where("post_id = ? and version < ?", post_id, version).order("version desc").first
|
PostArchive.where("post_id = ? and version < ?", post_id, version).order("version desc").first
|
||||||
end
|
end
|
||||||
|
|
||||||
def updater
|
|
||||||
User.find(updater_id)
|
|
||||||
end
|
|
||||||
|
|
||||||
def diff(version = nil)
|
def diff(version = nil)
|
||||||
if post.nil?
|
if post.nil?
|
||||||
latest_tags = tag_array
|
latest_tags = tag_array
|
||||||
@@ -237,13 +232,9 @@ class PostArchive < ActiveRecord::Base
|
|||||||
post.save!
|
post.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
def updater
|
|
||||||
User.find_by_id(updater_id)
|
|
||||||
end
|
|
||||||
|
|
||||||
def method_attributes
|
def method_attributes
|
||||||
super + [:obsolete_added_tags, :obsolete_removed_tags, :unchanged_tags, :updater_name]
|
super + [:obsolete_added_tags, :obsolete_removed_tags, :unchanged_tags, :updater_name]
|
||||||
end
|
end
|
||||||
|
|
||||||
memoize :previous, :post, :tag_array, :changes, :added_tags_with_fields, :removed_tags_with_fields, :obsolete_removed_tags, :obsolete_added_tags, :unchanged_tags
|
memoize :previous, :tag_array, :changes, :added_tags_with_fields, :removed_tags_with_fields, :obsolete_removed_tags, :obsolete_added_tags, :unchanged_tags
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user