flutterfire
flutterfire copied to clipboard
🐛 [cloud_firestore_odm] update functions doesn't include complex fields
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,
});```
Thanks for the report. Using the code sample provided above, seeing the same behavior as reported.
/cc @rrousselGit
I have same issue. Any timeline when this issue might be fixed?
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.
Moved to: https://github.com/FirebaseExtended/firestoreodm-flutter/issues/27