flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

🐛 [cloud_firestore_odm] update functions doesn't include complex fields

Open bsr203 opened this issue 3 years ago • 3 comments

I have modified the [movies model class] as below. The comments field is a nested list now. (https://github.com/firebase/flutterfire/blob/master/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/movie.dart)

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:cloud_firestore_odm/cloud_firestore_odm.dart';
import 'package:json_annotation/json_annotation.dart';

part 'movie.g.dart';

@JsonSerializable()
class Movie {
  Movie({
    this.genre,
    required this.likes,
    required this.poster,
    required this.rated,
    required this.runtime,
    required this.title,
    required this.year,
    this.comments,
  }) {
    _$assertMovie(this);
  }

  final String poster;
  @Min(0)
  final int likes;
  final String title;
  @Min(0)
  final int year;
  final String runtime;
  final String rated;
  final List<String>? genre;
  final List<Comment>? comments;
}

@Collection<Movie>('firestore-example-app')
final moviesRef = MovieCollectionReference();

@JsonSerializable()
class Comment {
  Comment({
    required this.authorName,
    required this.message,
  });

  final String authorName;
  final String message;

  factory Comment.fromJson(Map<String, dynamic> json) =>
      _$CommentFromJson(json);

  Map<String, dynamic> toJson() => _$CommentToJson(this);
}

as you can see, the update function doesn't include the comments field

  Future<void> update({
    String poster,
    int likes,
    String title,
    int year,
    String runtime,
    String rated,
    List<String>? genre,
  });```

bsr203 avatar Aug 26 '22 02:08 bsr203

Thanks for the report. Using the code sample provided above, seeing the same behavior as reported.

/cc @rrousselGit

darshankawar avatar Aug 26 '22 08:08 darshankawar

I have same issue. Any timeline when this issue might be fixed?

sajadmaster avatar Sep 02 '22 02:09 sajadmaster

This isn't supported for now. We'll see what can be done. But the logic for serializing those complex objects is a bit advanced.

For now, you can do:

moviesRef.doc(...).reference.update({'comments': [...]});

This allows invoking update without the ODM.

rrousselGit avatar Sep 06 '22 17:09 rrousselGit

Moved to: https://github.com/FirebaseExtended/firestoreodm-flutter/issues/27

TarekkMA avatar Jul 04 '24 07:07 TarekkMA