How to use "to Many" Relationships in Schema
sebtoombs opened this issue · comments
When attempting to encode a resource that has a relationship to a single other resource (i.e. what is often referred to as a "toOne" resource) the Parser throws the following error:
Schema is not registered for a resource at path "toOneResource"
Note that the error only occurs when the relationship is not empty. If the relationship is empty, the data is generated correctly. (e.g. below)
data: {}
instead of
data: []
Is this a bug, or are "toMany" relationships not supported?
It supports both types of relationships to single resource and collections. Encoder understands that array
, Iterator
or Traversable
are toMany
relationships and acts accordingly. You just provide your data in Schema
and encoder does the rest. That's an example for both types of relationships and how encoding result looks like.
Apart from numerous encoding samples there is a wiki as well.
Thanks, I had already reviewed all of that information.
Turned out the issue was with types, Doctrine returning a proxy but the Schema expecting an entity.
Thanks for the reply.