FirebaseExtended / firestoreodm-flutter

BSD 3-Clause "New" or "Revised" License
36 stars 11 forks source link

[cloud_firestore_odm] update functions doesn't include complex fields #27

Open TarekkMA opened 4 months ago

TarekkMA commented 4 months ago

Moved to: https://github.com/firebase/flutterfire/issues/9428

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,
  });```