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

Return value from realm.write #2237

Closed
Andreyco opened this issue Jan 24, 2019 · 10 comments · Fixed by #3937
Closed

Return value from realm.write #2237

Andreyco opened this issue Jan 24, 2019 · 10 comments · Fixed by #3937

Comments

@Andreyco
Copy link

Andreyco commented Jan 24, 2019

Allow returning value from realm.write

E.g.

const user = realm.write(() => {
  return realm.create('User', {})
})

If you accept this feature request, I can provide PR.

@Andreyco
Copy link
Author

Andreyco commented Feb 4, 2019

No interest?

@nirinchev
Copy link
Member

I think it makes sense and doesn't sound like a breaking change. We'd be happy to review a PR for it. cc @kraenhansen @cmelchior

@kneth
Copy link
Contributor

kneth commented Aug 16, 2019

So only the last created object should be returned?

@davidwadge
Copy link

Is this really not possible?

@nirinchev
Copy link
Member

@kneth seeing your comment only now - I think realm.write should just return whatever the callback returned. So if you did:

let foobar = realm.write(() => {
  // create objects, update them, etc.
  return { "foo": "bar" }
});

foobar.foo == "bar";

@kraenhansen
Copy link
Member

kraenhansen commented Apr 23, 2020

I agree - this should be straight forward to implement and very valuable.

@nhadro
Copy link

nhadro commented May 13, 2020

I'll add that this would very valuable and would definitely appreciate this addition.

@RealmBot
Copy link
Collaborator

➤ Brian Munkholm commented:

PR's are highly appreciated!

@ianpward
Copy link

@takameyer This came up in our user interview today - can we add this to our potential future API plan please?

@takameyer
Copy link
Contributor

@ianpward I'll add it in. Looks like a very useful feature.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.