Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Object Not Persisting After PutAndGetAsync/PutAsync/Put in ObjectBox #667

Open
yashanghan22 opened this issue Aug 30, 2024 · 7 comments
Labels
more info required Needs more info to become actionable. Auto-closed if no response.

Comments

@yashanghan22
Copy link

yashanghan22 commented Aug 30, 2024

Why is it that when we update a list object and store it in ObjectBox using PutAndGetAsync, the logged value shows the updated ObjectBox, but in the next line, when we call the get method to retrieve the same object and print its value in the console, it still shows the old value?

Build info

  • objectbox version: 4.01
  • Flutter/Dart version: 3.19.6/3.2.6
  • Build OS: Windows 10
  • Deployment OS or device: windows

Expected behavior

when i put updated ToMany List in objectbox it is not updating in local storage insertion and deletion is working fine but modificatin is not working.

Actual behavior

it should be update in local storage.

Code

Code
final object = _getBillingStateById();
    var inx =
        object.challanList.indexWhere((element) => element.id == challan.id);
    if (inx < 0) {
      return right(Failure());
    }
    final ch = ChallanObjectModel.fromModel(challan);
    ch.partyName.target = PartyObjectModel.fromModel(challan.partyName);
    ch.qaulity.target =
        QaulityObjectModel.fromModel(challan.qaulity ?? QaulityModel());
    object.challanList[inx] = ch;
    logger.f('aaa: ${object.challanList[inx].remarks}');
    var i = await objectbox.billingStateBox.putAndGetAsync(object);
    logger.i('bbb;${i.challanList[inx].remarks}');
    logger.w(
        'ccc: ${(await objectbox.billingStateBox.getAsync(object.id))?.challanList[inx].remarks}');
    return left(ch.id);

Logs, stack traces

TODO Add relevant logs, a stack trace or crash report.

Logs
- flutter: │ aaa: 123
- flutter: │ bbb;123
- flutter: │ ccc: 43
@yashanghan22 yashanghan22 added the bug Something isn't working label Aug 30, 2024
@greenrobot-team
Copy link
Member

greenrobot-team commented Sep 2, 2024

Thanks for reporting! Is it possible that there are multiple objects inside challanList and the index inx for 123 is different?

Note: I labeled this issue with "more info required" so it will auto-close in a few days if there are no follow-up comments.

@greenrobot-team greenrobot-team added more info required Needs more info to become actionable. Auto-closed if no response. and removed bug Something isn't working labels Sep 2, 2024
@yashanghan22
Copy link
Author

yashanghan22 commented Sep 2, 2024

@greenrobot-team , inx is correct and i already checked.

@github-actions github-actions bot removed the more info required Needs more info to become actionable. Auto-closed if no response. label Sep 3, 2024
@greenrobot-team
Copy link
Member

Thanks! Then, there must be an issue somewhere else. Please provide enough additional information so I can reproduce this!

@greenrobot-team greenrobot-team added the more info required Needs more info to become actionable. Auto-closed if no response. label Sep 3, 2024
@yashanghan22
Copy link
Author

yashanghan22 commented Sep 3, 2024

@greenrobot-team Here is some info regarding models

``This is my main Object:

@Entity()
class BillingStateObjectboxModel {
BillingStateObjectboxModel({
    required this.id,
    this.challanList = const [],
  });
@Id()
  Int id;
ToMany<ChallanObjectModel> challanList = ToMany();
}

challan object Model

class ChallanObjectModel {
  @Id()
  int id;
  double? amount;

  String? broker;

  double? cgst;

  String? challanNo;

@Property(type: PropertyType.date)
  DateTime? date;

  double? igst;

 @Property(type: PropertyType.floatVector)
  List<double>? meters;

  String? onAc;

  String? outside;

  String? outstate;

  PartyObjectModel? partyName;

  QaulityObjectModel? qaulity;

  double? rate;

  String? remarks;

  double? sgst;

  double? totalEnt;

  String? voucherNo;

ChallanObjectModel({
    this.id = 0,
    this.amount,
    this.broker,
    this.cgst,
    this.challanNo,
    this.date,
    this.igst,
    this.meters,
    this.onAc,
    this.outside,
    this.outstate,
    this.rate,
    this.remarks,
    this.sgst,
    this.totalEnt,
    this.voucherNo,
  });
}

The ChallanObjectModel is part of the BillingStateObjectboxModel. When I try to update any value in the challan object, it doesn't update. The update function is already shown in the first comment. I think this information should be enough, but let me know if you need more details.

@github-actions github-actions bot removed the more info required Needs more info to become actionable. Auto-closed if no response. label Sep 4, 2024
@greenrobot-team
Copy link
Member

Thanks for the details. I tried to verify this and:

  • when exchanging an object of a ToMany relation via list index, then
  • saving the object owning the ToMany with putAndGetAsync(), then
  • retrieving the object with getAsync()

the relation is properly updated.

  test('gh-667-put-and-get-async', () async {
    final box = store.box<BillingStateObjectboxModel>();
    final object = BillingStateObjectboxModel(id: 0);
    object.challanList.add(ChallanObjectModel(remarks: 'first'));
    box.put(object);
    
    final ch = ChallanObjectModel(remarks: 'second');
    object.challanList[0] = ch;
    var objectPut = await box.putAndGetAsync(object);
    print(objectPut.challanList[0].remarks);
    
    final objectGet = await box.getAsync(object.id);
    print(objectGet!.challanList[0].remarks);
  });

So this must be an issue with your implementation. In this case I can only help with a working test case that reproduces this.

Side note, this is not valid Dart syntax for me:

this.challanList = const []

Can you double-check this is similar to what the class actually looks like?

@greenrobot-team greenrobot-team added the more info required Needs more info to become actionable. Auto-closed if no response. label Sep 4, 2024
@yashanghan22
Copy link
Author

this.challanList = const []

What's the problem with this? Can you suggest a solution, please?

@github-actions github-actions bot removed the more info required Needs more info to become actionable. Auto-closed if no response. label Sep 5, 2024
@greenrobot-team
Copy link
Member

For me Dart says this is invalid syntax and can't compile.

Anyhow, that's not the main issue:

I can only help with a working test case that reproduces this.

@greenrobot-team greenrobot-team added the more info required Needs more info to become actionable. Auto-closed if no response. label Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more info required Needs more info to become actionable. Auto-closed if no response.
Projects
None yet
Development

No branches or pull requests

2 participants