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

[DOC] Improve warning for mismatched id in store.findRecord #4609

Merged
merged 1 commit into from
Oct 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions addon/-private/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,8 @@ Store = Service.extend({

/**
This method makes a request for one record, where the `id` is not known
beforehand (if the `id` is known, use `findRecord` instead).
beforehand (if the `id` is known, use [`findRecord`](#method_findRecord)
instead).

This method can be used when it is certain that the server will return a
single object for the primary data.
Expand Down Expand Up @@ -1208,8 +1209,7 @@ Store = Service.extend({

The request is made through the adapters' `queryRecord`:

```javascript
// app/adapters/user.js
```app/adapters/user.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change looks unintentional

Copy link
Member

@bmac bmac Oct 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is intentional. The markdown parser for JavaScript blocks in the API guides has an enhancement to show the filename in the heading when the filename is included after the three backticks. It uses the file extension to detect what source highlighting should be used.

screen shot 2016-10-21 at 9 54 17 am

vs

screen shot 2016-10-21 at 9 54 47 am

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep yep yep, that was the intention.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that's cool.

TIL

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL too :D

import DS from "ember-data";

export default DS.Adapter.extend({
Expand Down
2 changes: 1 addition & 1 deletion addon/-private/system/store/finders.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function _find(adapter, store, typeClass, id, internalModel, options) {
var payload = normalizeResponseHelper(serializer, store, typeClass, adapterPayload, id, 'findRecord');
assert('Ember Data expected the primary data returned from a `findRecord` response to be an object but instead it found an array.', !Array.isArray(payload.data));

warn(`You requested a record of type '${typeClass.modelName}' with id '${id}' but the adapter returned a payload with primary data having an id of '${payload.data.id}'. Looks like you want to use store.queryRecord instead http://emberjs.com/api/data/classes/DS.Store.html#method_queryRecord`, payload.data.id === id, {
warn(`You requested a record of type '${typeClass.modelName}' with id '${id}' but the adapter returned a payload with primary data having an id of '${payload.data.id}'. Use 'store.findRecord()' when the requested id is the same as the one returned by the adapter. In other cases use 'store.queryRecord()' instead http://emberjs.com/api/data/classes/DS.Store.html#method_queryRecord`, payload.data.id === id, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

id: 'ds.store.findRecord.id-mismatch'
});

Expand Down