Skip to content

Support for temporary items #284

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

Merged
merged 3 commits into from
Feb 17, 2016
Merged

Conversation

davincho
Copy link
Contributor

Behaviour of inject, filter and isNew implemented as proposed in ticket #197

There are still some open points such as DSSave and DSCreate. @jmdobry maybe you can make some comments if I am on the right track.

Behaviour of inject, filter and isNew implemented as proposed in ticket
@jmdobry
Copy link
Member

jmdobry commented Dec 23, 2015

I'm not sure I like the performance implications of storing an array of temporary IDs, and having to search the array on every iteration of the filter callback. What about actually attaching a property to a temporary item itself that marks it as temporary? Or instead of an array of IDs, keep an index of IDs for O(1) lookup times?

@davincho
Copy link
Contributor Author

Yes that make sense. I was thinking about a property for each instance but I did not want to mix data properties and internal properties of an instance. Maybe I missed something - is there a way of hiding an internal property?

@davincho
Copy link
Contributor Author

@jmdobry I am thinking about what would be the best way of replacing the artifical ID with the one returned by the server. Foreign keys of other items referencing the temporary item have to be updated as well.

@jmdobry
Copy link
Member

jmdobry commented Dec 28, 2015

I hadn't considered that, I think I'm losing enthusiasm for this feature.

@davincho
Copy link
Contributor Author

Mh too bad - I think this feature could be really helpful. I thought about if it would be possible keeping the original ID (=guid) internally, while exposing the updated Id to the user. Or do you prefer to abandon the feature completely?

@jmdobry
Copy link
Member

jmdobry commented Dec 28, 2015

I'm working on this in v3, I'll see if I can find a nice way to back port it.

jmdobry added a commit that referenced this pull request Feb 17, 2016
@jmdobry jmdobry merged commit 5ab93d2 into js-data:master Feb 17, 2016
jmdobry added a commit that referenced this pull request Feb 18, 2016
Closes #273
Closes #284
Closes #290
Closes #305

Fixes #251
Fixes #262
Fixes #272
Fixes #304
@jessehouchins
Copy link

@jmdobry Am i right in thinking that this only handles temporary ids for a specific resource and DOES NOT update relations when the new id is returned from the server?

@jmdobry
Copy link
Member

jmdobry commented Mar 1, 2016

Right

On Mon, Feb 29, 2016, 5:05 PM Jesse Houchins [email protected]
wrote:

@jmdobry https://github.com/jmdobry Am i right in thinking that this
only handles temporary ids for a specific resource and DOES NOT update
relations when the new id is returned from the server?


Reply to this email directly or view it on GitHub
#284 (comment).

@rgant
Copy link

rgant commented Feb 14, 2017

Is there any documentation for this feature?

Throughout my code when creating new resources I've had to do things like:

var newStrategy = DS.createInstance('report_strategies', {reportid: theReport.id, id: ''});

But maybe I should have been doing:

var newStrategy = DS.createInstance('report_strategies', {reportid: theReport.id}, {temporary: true});

I don't see the word "temporary" anywhere when searching the documentation.

@rgant
Copy link

rgant commented Feb 15, 2017

Seems like that won't work because resolveId doesn't know about the temporary option and many of promises check for the id being a string or number and reject immediately if not. So I guess this doesn't really help.

I'm not finding the documentation I need to understand the whole process of how to create new resources in the real world.

@jmdobry
Copy link
Member

jmdobry commented Feb 16, 2017

In V3 records have an isNew() method, which just returns true or false based on whether the record has a primary key. Records with and without primary keys can be inserted into Collections. Records without primary keys are invisible to certain operations, like Collection#get(id). Collections also have a helper method for retrieving unsaved records from the collection (since they don't have IDs): Collection#unsaved()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants