Skip to content

[DOC release] Change misleading documentation for AdapterPopulatedRecordArray - #5620

Merged
runspired merged 1 commit into
warp-drive-data:masterfrom
happycollision:patch-1
Sep 5, 2018
Merged

[DOC release] Change misleading documentation for AdapterPopulatedRecordArray#5620
runspired merged 1 commit into
warp-drive-data:masterfrom
happycollision:patch-1

Conversation

@happycollision

@happycollision happycollision commented Sep 1, 2018

Copy link
Copy Markdown
Contributor

In my experimentation, I've discovered that though the promise returned from store.query() does have array-like methods on it, the actual AdapterPopulatedRecordArray is what the promise resolves to. The promise does not behave like a proxy (or what I think Ember Proxies do...). The documentation for store.query states this plainly, but the documentation here misrepresented that.

For example, the original code actually would behave like this:

  // GET /users?isAdmin=true
  var admins = store.query('user', { isAdmin: true });

  admins.then(function() {
    console.log(admins.get("length")); // Throws: "admins.get" is not a function
  });

@happycollision

Copy link
Copy Markdown
Contributor Author

I'm about to force push to change the commit message to meet your standards.

In my experimentation, I've discovered that though the promise returned from `store.query()` does have array-like methods on it, the actual `AdapterPopulatedRecordArray` is what the promise *resolves to*. For example, the `length` property of the object returned from `store.query` will always be `0`. The object which the promise resolves to will represent the actual length of the records that were queried.

The documentation for `store.query` states plainly that the AdapterPopulatedRecordArray is the *resolution* of the promise, but the documentation here misrepresented that.

For example, the original code actually would behave like this:
```javascript
  // GET /users?isAdmin=true
  var admins = store.query('user', { isAdmin: true });

  admins.then(function() {
    console.log(admins.get("length")); // Throws: "admins.get" is not a function
  });
```
@happycollision

Copy link
Copy Markdown
Contributor Author

And once more to remove things inside the commit message where I am speaking a little bit about things I don't know.

I realize that when I read commit messages that are merged, I take them to be the actual truth. In my original commit message, I made a comment referring to Ember's ProxyObjects, but I am really not 100% sure how those work. And that comment is actually not pertinent to this change anyhow.

@runspired

Copy link
Copy Markdown
Contributor

I'm in favor of this documentation change; however, historically speaking query did return a PromiseArray. we may have broken something over time without realizing it. In today's world of async await and better promise knowledge, just working with the promise is preferred anyway.

@runspired
runspired merged commit 1cac25e into warp-drive-data:master Sep 5, 2018
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.

2 participants