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

Direct change of an related object via the main saved obj. #619

Open
RolandDaum opened this issue Mar 26, 2024 · 1 comment
Open

Direct change of an related object via the main saved obj. #619

RolandDaum opened this issue Mar 26, 2024 · 1 comment
Labels
question How to do something/general question

Comments

@RolandDaum
Copy link

Hello everybody. First of all, this is not a bug, just a question. Why is it not possible to change a value of an related object via the first object that has been saved?

@Entity()
// ignore: camel_case_types
class OB_userdata {
  @Id()
  int id = 0;
  
  List<String> kurse = [];
  String jahrgang = '';
  final secureCredentials = ToOne<SecureCredentials>();
}
@Entity()
class SecureCredentials {
  int id = 0;
  String username = '';
  String password = '';

  void changePassword(String newpassword) {
    this.password = newpassword;
  }

  SecureCredentials({required this.username,required this.password});
} 

Here for example I want to change the username or password which is a related/linked object of the userdata object. But in order to change anything, I have to get the SecureCredentials object as an extra variable, then change the values there and override it in the OB_userdata object (OB_userdata.secureCredentials.target = SecureCredentials(username: 'username', password: 'password');). Thats kind a complecated. In Addition the changePassword Method is also not working.

So my question is, am I blind and didn't see something or is it just the way it is and I have to accept it?

Thanks for any kind of help.
R. Daum

@RolandDaum RolandDaum added the bug Something isn't working label Mar 26, 2024
@greenrobot-team greenrobot-team added question How to do something/general question and removed bug Something isn't working labels Apr 8, 2024
@greenrobot-team
Copy link
Member

greenrobot-team commented Apr 8, 2024

Get the target object, but then instead of putting it with the parent object put it into its own box?

Changes on related objects (to-one or to-many) are not saved when putting the parent/source object. There is an exception, if the related object was not inserted, yet. Then ObjectBox will insert it. Otherwise, ObjectBox will only update the relation.

Let me know if that helps!

@greenrobot-team greenrobot-team added the more info required Needs more info to become actionable. Auto-closed if no response. label Apr 8, 2024
@github-actions github-actions bot removed the more info required Needs more info to become actionable. Auto-closed if no response. label Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question How to do something/general question
Projects
None yet
Development

No branches or pull requests

2 participants