I'm getting the response similar to the following format from server.
{"channels": [{"name":"discovery", "id":"12",
"details":{"src":"link", "logo":"imagelink"}}]
I'm planning to use Redux-Orm to manage the state in the store. When I'm trying to define the model, I'm having confusions. One way is to define Channel Model with name and id as attributes, details as one to one mapping and Details Model with src, logo attributes as below.
const channel = class Channel extends Model {};
channel.fields = {
name: attr(),
id: attr(),
details: oneToOne('details', 'channels')
}
const details = class Details extends Model {};
details.fields = {
src: attr(),
logo: attr()
}
Or Should I define a single model class which represents the response as is? If so, how to define and access it?
If you want to have a
Detailmodel, your backend must identify it with anidlike theChannelmodel, and then you may do aoneToOnerelation.That being said, using a single model or two is totally depending on how they'll interact in your app, and may grow. If your
detailsfield won't grow much more, my totally personal point of view would be to keep it in a singleChannelmodel. you'd access it throughchannel.detailsorchannel.details.srctransparently.IMO,
oneToOnesimple relation like that does not need a specific model.