merefield
(Robert)
September 16, 2022, 12:56pm
5
Here are examples of their use:
end
end
on(:post_destroyed) do |post|
if Assignment.exists?(target_type: "Post", target_id: post.id, active: true)
Assignment.where(target_type: "Post", target_id: post.id).update_all(active: false)
MessageBus.publish("/topic/#{post.topic_id}", reload_topic: true, refresh_stream: true)
end
# small actions have to be destroyed as link is incorrect
PostCustomField
.where(name: "action_code_post_id", value: post.id)
.find_each do |post_custom_field|
next if post_custom_field.post == nil
if ![Post.types[:small_action], Post.types[:whisper]].include?(
post_custom_field.post.post_type,
)
next
end
post_custom_field.post.destroy
end
and
end
end
def create!
post = get_existing_post || post_creator.create!
update_since_id
post
end
def get_existing_post
existing_post_ids = PostCustomField
.where(name: "autobot_source_url", value: source_url)
.where(name: "autobot_campaign_id", value: campaign["id"])
.pluck(:post_id)
return if existing_post_ids.blank?
Post.unscoped.find(existing_post_ids).last
end
private
Make sure you are familiar with Rails Active Record Model concepts, because you’d normally want to do everything via Ruby on Rails rather than directly on the database.