You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you have a similar data type, but it has been modelled as two separate things (for internal reasons you don't wish to inflict on API consumers); you may try to do something like:
class SerializableFoo < ::JSONAPI::Serializable::Resource
type "foobar"
attributes :bizz, :buzz, :things_that_arent_id
class SerializableBar < SerializableFoo
type "foobar"
This works until you create two different records with the same ID and pass them off for serialization in the same payload - only the first record will be rendered.
The workaround is to define id:
class SerializableFoo < ::JSONAPI::Serializable::Resource
type "foobar"
id { "foo-#{@object.id}" }
class SerializableBar < SerializableFoo
type "foobar"
id { "bar-#{@object.id}" }
However; this is difficult to discover. IE: Where used with activerecord, 95% of the time this will be "fine" in production if you have different IDs, until you hit a rare conflict.
Consider:
Expanding the examples in the readme?
Emitting warnings if you push something onto the rendering stack that already exists and is different to the existing record or came from a different serializer?
The text was updated successfully, but these errors were encountered:
Not sure if this is better here; or in another place like jsonapi-rb/jsonapi-renderer#34
When you have a similar data type, but it has been modelled as two separate things (for internal reasons you don't wish to inflict on API consumers); you may try to do something like:
This works until you create two different records with the same ID and pass them off for serialization in the same payload - only the first record will be rendered.
The workaround is to define id:
However; this is difficult to discover. IE: Where used with activerecord, 95% of the time this will be "fine" in production if you have different IDs, until you hit a rare conflict.
Consider:
The text was updated successfully, but these errors were encountered: