isar_crdt icon indicating copy to clipboard operation
isar_crdt copied to clipboard

Does not work with embedded objects

Open eelco2k opened this issue 1 year ago • 4 comments

Unfortunately it does not work with @embedded objects. It just sees it as an insert. (for .toJson() i'm using the json_annotation package)

for example:

@JsonSerializable()
@collection
class Orders extends CrdtBaseObject {
  Id id = Isar.autoIncrement;
  @Index(unique: true, replace: true)
  List<CartModel>? cart;
  int? userId;
  Table? table;
  double? orderTotal;
  double? taxTotal;
}

@JsonSerializable()
@embedded
// even not working with: class CartModel extends CrdtBaseObject {}
class CartModel {
  String productUuid = uuid.v4();
  double? price;
  double? discountAmount;
  double? quantity;
  double? taxAmount;
}

It inserts the whole json ( .toJson() ) in the crdt entries table (value column) as 1 crdt event.

So i guess it only works with the Int, String, and simple Lists..

Furthermore what could be the case is that it needs an id autoIncrement which this embedded object does not have. in isar_extensions.dart the putAllChanges() relies on schema.getId() for new and changed entries.

specific:

final elementsMatch =
        elements.splitMatch((e) => schema.getId(e) == Isar.autoIncrement);

eelco2k avatar Oct 03 '23 19:10 eelco2k