Skip to content

Commit

Permalink
fix: array resource adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob committed Feb 21, 2025
1 parent 6fef8ba commit 7ee642a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/avo/resources/array_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class ArrayResource < Base
class << self
def model_class
@@model_class ||= Object.const_set(
name,
class_name,
Class.new do
include ActiveModel::Model

class << self
def primary_key = nil

def all = "Avo::Resources::#{name}".constantize.new.fetch_records
def all = "Avo::Resources::#{class_name}".constantize.new.fetch_records
end
end
)
Expand All @@ -40,7 +40,7 @@ def find_record(id, query: nil, params: nil)

def fetch_records(array_of_records = nil)
array_of_records ||= records
raise "Unable to fetch any #{name}" if array_of_records.nil?
raise "Unable to fetch any #{class_name}" if array_of_records.nil?

# When the array of records is declared in a field's block, we need to get that block from the parent resource
# If there is no block try to pick those from the parent_record
Expand Down Expand Up @@ -69,7 +69,7 @@ def fetch_records(array_of_records = nil)
keys = array_of_records.flat_map(&:keys).uniq

Object.const_set(
name,
class_name,
Class.new do
include ActiveModel::Model

Expand All @@ -82,7 +82,7 @@ def fetch_records(array_of_records = nil)
end
)

custom_class = name.constantize
custom_class = class_name.constantize

# Map the records to instances of the dynamically created class
array_of_records.map do |item|
Expand Down

0 comments on commit 7ee642a

Please sign in to comment.