-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
first request to findAll does not resolve correctly #1013
Comments
@dagda1 Actually, DS.Model.find() return a 'promistified' RecordArray whch promise is resolved when the recordarray is loaded (ie its isLoaded propery is true). The problem is that DS.Model.find() is loaded as soon as the array is created, as a consequence the promise is resolved. In order to fix your problem (because I think you want to return a live array), something like this should work:
This way, under the hood, you are calling a findQuery, which is loaded when the backend returns the records, not at the array creation. cc/ @tchak, I'd like you to confirm this though, to be sure I'm right. |
@sly7-7 this sounds like the perfect amount of hax to be correct. This would not surprise me at all. |
That does indeed work. |
Yeah, so I would say it's not an "issue" because this is the way it's intended to work. But this should definitely change. I really hope @tchak and @stefanpenner could work together in order to make ember-data and promises working great together. |
I think the current behaviour of find will be unexpected to most people. It was to me anyway. |
Confirm. The current behavior makes no sense. On Fri, May 31, 2013 at 11:08 PM, Paul notifications@github.com wrote:
|
@dagda1 @ahawkins I agree with you, but as explained here #735 (comment) we have to define when should we consider the array as "loaded". |
I faced the same issue. I am using ruby on rails with include_root_in_json set to true.. { var reference = this.extractRecordRepresentation(loader, type, objects[i]); // <-- changed this to pass objects[i][root] to the method. That fixed it for me. |
@shonsaoji I think you should response: {
verticals: [{
id: 1, name: "vertical_one"
}, {
id: 2, name: "vertical_two"
}]
} You could use active_model_serializers to serialize your models. |
@dagda1 @ahawkins @sly7-7 what happens if you create a record on the client before calling
The only part missing is |
My concern would be that people new to ember (which we need to encourage more of) would not know what to make of:
Maybe we should give it some sugar in the form of a nicer name that delegates to this? findAll would be my choice (joke) :) |
@dagda1 People new to ember should not need it :) |
This is definitely a bug. Maybe not implementation bug (if it is intented to be so), but design bug. isLoaded should become true only when finished loading data from the server. If there is a need in Ember internal workings to observer when the "live array" becomes initialised then please implement a isArrayInitilised state for this. Or please at least add isReallyReallyLoaded state so we can build applications. find({}) workaround to trigger findQuery is not a solution, but a hack. It does not work for example for FixtureAdapter. |
@jaaksarv I have to agree. IsLoaded should not be ambiguous. You would only ever expect that isLoaded would equal true if it had finished loading data from the server. |
If you have no server then you need to somehow set the isLoaded to true initially but it should not set out with a default of true. |
Why you don't use |
@tchak If you have no server then isLoaded should become true once the array is populated with data. I'm currently using FixtureAdapter for development before connecting my application to the server. FixtureAdapter has some dalay in it to emulate asynchronous server communication behavior. And with FixtureAdapter the isLoaded property also becomes true before the array is filled with data. |
@tchak isUpdating does not help. isUpdating flag will become true and then false, both before the array is populated. I also went through ember-data code (v0.13). There are no comments on isUpdating property on DS.RecordArray so hard to tell what it is and how it should behave. From the code I can tell that store.didUpdateAll will set isUpdating to false, but this will happen before serializer.extractMany is called. Anyway I think that isLoaded should be fixed for findAll. isLoaded should have the same meaning whatever loading type is used (find single record, findAll, findQuery, findMany). Current behavior is confusing. If there is need to have different logic for "live array" then some other property should be used for this and not isLoaded. |
@jaaksarv you right about The main issue we have now is the fact that records/record arrays are promises them selves. They are resolved on "load" and stay this way. It need to change. The confusion is related to the fact tat In sproutcore data store the concept of "live query" and "remote query" were more separated. I agree that by providing a more unified api we introduced some confusion. I think by solving the promises situation and with better documentation we should be able solve all the use cases. |
@tchak : i have a problem here.
And here is my json {
users: [{
name: "Nadeem",
comments: [{
id: 1
},
{
id: 2
}]
}]
} But when i console "all", it just shows a class object. Something like this. even i have tried this: console.log(all.get('users')) |
@nadeemyasin61 what you expect to see? You got a |
@tchak thanks man. I was trying to use like a regular JS array with []. Make it to work. 👍 |
We'll be changing the way promises work soon, which should in turn resolve this. |
I should have said "changing the way we use promises". We will not be changing the actual behavior of promises themselves :) |
I am using the latest from master (revision 13)
I am finding that the first request to any resource returns 0 records on the first call to findAll, for example
What I am finding is that the console.log statement above will log 0 but if I then type:
into the console after the page has refreshed and a call to findAll has been made, the length is as I would expect, i.e. greater than 0.
This happens for any resource, I have stepped through the code and the json is getting materialized into the models but for some reason, the record array is empty.
I have stepped through the code and it appears that the promise is resolving before didFIndAll is called.
I cannot create a fiddle for this as it is only happening with the rest adapter.
The text was updated successfully, but these errors were encountered: