# 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