about summary refs log tree commit diff
path: root/app/models/account_metadata.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/account_metadata.rb')
-rw-r--r--app/models/account_metadata.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/app/models/account_metadata.rb b/app/models/account_metadata.rb
new file mode 100644
index 000000000..1085d7f14
--- /dev/null
+++ b/app/models/account_metadata.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+# == Schema Information
+#
+# Table name: account_metadata
+#
+#  id         :bigint(8)        not null, primary key
+#  account_id :bigint(8)        not null
+#  fields     :jsonb            not null
+#
+
+class AccountMetadata < ApplicationRecord
+  include Cacheable
+
+  belongs_to :account, inverse_of: :metadata
+  cache_associated :account
+
+  def fields
+    self[:fields].presence || {}
+  end
+
+  class << self
+    def create_or_update(fields)
+      create(fields).presence || update(fields)
+    end
+
+    def create_or_update!(fields)
+      create(fields).presence || update!(fields)
+    end
+  end
+end