Open srozen opened 11 months ago
@srozen there is!
...unfortunately it expects the JSON to appear in a certain way though, ie:
{
"id": 1,
"employees": [],
"articles": [],
}
...so in your example a bit of a workaround may be required. 🤔
You could either massage the incoming JSON in Faraday before passing it on to Spyke to fit the format above, or perhaps use a class to join them together:
class Book < Spyke::Base
has_one :resources, class_name: "BookResources", uri: nil
end
class BookResources < Spyke::Base
has_many :employees, uri: nil
has_many :articles, uri: nil
end
book.resources.employees # => []
book.resources.articles # => []
Hello, is there a way to make the association definition to pick up nested resources from the JSON payload?
Let's say we have a
Shop
model withArticles
andEmployees
, but the JSON payload when fetching theShop
is the following :How could one define the
has_many
such thatshop.employees
returns the Spyke association?