firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.63k stars 3.95k forks source link

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

Closed bsr203 closed 2 months ago

bsr203 commented 2 years ago

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,
  });```
darshankawar commented 2 years ago

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

/cc @rrousselGit

sajadmaster commented 2 years ago

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

rrousselGit commented 2 years ago

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.

TarekkMA commented 2 months ago

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