Skip to content

Inserting Data With Default Values #57

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

Closed
Zenthae opened this issue Apr 16, 2021 · 10 comments · Fixed by #68
Closed

Inserting Data With Default Values #57

Zenthae opened this issue Apr 16, 2021 · 10 comments · Fixed by #68
Assignees
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@Zenthae
Copy link
Contributor

Zenthae commented Apr 16, 2021

https://next.vuex-orm.org/guide/repository/inserting-data.html#inserting-data-with-default-values

The new method will create a record with all fields filled with default values defined in the model.

const user = store.$repo(User).new()

// { id: '$uid1', name: '' }

that's what's written on the doc, but the new() method doesn't exist in practice ? so how i'm supposed to add data ?

this.$store.$repo(User).insert(new User()); ? that's what i'm using at the moment, but i'm not sure if it's the right way to do it

@cuebit cuebit added the documentation Improvements or additions to documentation label Apr 16, 2021
@cuebit
Copy link
Member

cuebit commented Apr 16, 2021

Ah yea, this was replaced with $repo(User).make()

Correct. This method appears to be missing.

Docs need updating! Thanks for spotting this.

@cuebit cuebit added the bug Something isn't working label Apr 16, 2021
@Zenthae
Copy link
Contributor Author

Zenthae commented Apr 16, 2021

@cuebit you haven't told me what should i use to do the same though. is there a way ?

@kiaking
Copy link
Member

kiaking commented Apr 17, 2021

@Zenthae It might not be suitable solution but you must at least give 1 default field value. Like insert({ name: '' }).

Or should we create a record if users pass in an empty object 🤔 ?

@cuebit
Copy link
Member

cuebit commented Apr 17, 2021

Sorry, I was meant to respond to this but found a bug where add was actually doing exactly what @Zenthae was asking about when it shouldn't of been! That's been resolved by #58 since.

@kiaking this needs to be implemented right? I don't think a query method currently exists to support this.

@kiaking
Copy link
Member

kiaking commented Apr 17, 2021

@cuebit Yap it should! But, just wondering if it might make sense to actually create a new record when passing in empty object {}. It does the same thing as new method, but, it might make sense.

Either way I think having new method make sense as an API. Easier to understand so 👀

@cuebit
Copy link
Member

cuebit commented Apr 17, 2021

True. But then there has to be the uid attribute caveat in the docs for all the persist methods 😂 maybe new is a safe bet.

@kiaking
Copy link
Member

kiaking commented Apr 17, 2021

Ah very good point. Yeah lets go with new method only for now 😆

@Zenthae
Copy link
Contributor Author

Zenthae commented Apr 20, 2021

any news on this ?

@cuebit
Copy link
Member

cuebit commented Apr 20, 2021

Should have a PR by the end of the week 👍

@Zenthae
Copy link
Contributor Author

Zenthae commented May 1, 2021

👋

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
3 participants