lib/yext/api/concerns/account_child.rb in yext-api-0.1.5 vs lib/yext/api/concerns/account_child.rb in yext-api-0.1.7
- old
+ new
@@ -27,10 +27,11 @@
def ensure_relation(klass)
[Yext::Api::KnowledgeApi::AccountSettings::Account, Yext::Api::AdministrativeApi::Account].each do |account_class|
next if account_class.association?(klass)
klass_uri = klass.instance_variable_get(:@uri)
+
klass_uri ||= klass.send(:default_uri)
helper_warnings(account_class, klass, klass_uri)
add_has_many_relation(account_class, klass, klass_uri)
end
@@ -77,10 +78,12 @@
Yext::Api::KnowledgeApi::AccountSettings::Account.new(id: account_or_id)
end.public_send(Yext::Api::Concerns::AccountChild.association_name(self))
end)
Yext::Api::Concerns::AccountChild.ensure_relation(self)
+
+ after_save :save_account_id
end
class_methods do
def all
if current_scope.nil?
@@ -108,13 +111,33 @@
def scope_args(account_scope = false)
args = current_scope&.params&.dup || {}
args[:account_id] ||= Yext::Api.configuration.param_account_id
+ # account_scope means that the scope will be applied to an Account rather than a
+ # relation off of an Account.
args[:id] = args.delete(:account_id) if account_scope
args
end
+ end
+
+ # rubocop:disable Naming/MethodName
+
+ # Yext field names don't match the Ruby naming standard, this is the field name they use.
+ # Because I use `account_id` in the route, I need that attribute defined. Because
+ # Yext uses accountId, when it is set, I need to set `account_id` so they will match.
+ def accountId=(value)
+ super
+ attributes[:account_id] = value
+ end
+
+ # rubocop:enable Naming/MethodName
+
+ private
+
+ def save_account_id
+ attributes[:account_id] = attributes[:accountId] if attributes.key?(:accountId)
end
end
end
end
end