Skip to content

How to save new entity with nested entities included #224

Closed Answered by frank06
andreystavitsky asked this question in Q&A
Discussion options

You must be logged in to vote

The default will send IDs so if your model doesn't have an ID it won't send anything. If you need to send nested models override the default serializer. In your place adapter:

  @override
  Future<Map<String, dynamic>> serialize(T model,
      {bool withRelationships = true}) async {
    final map = await super.serialize(model, withRelationships: true);
    map['photos'] = mapIdsIntoModels(map['photos']);
    return map;
  }

To map IDs into models you can use the finders for example await photoAdapter.findOne(photoId, remote: false) and then turn them into maps via photoAdapter.serialize(model).

To get the photo adapter inside your place adapter, look it up in adapters

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@andreystavitsky
Comment options

@frank06
Comment options

Answer selected by andreystavitsky
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants