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

fix createRecord error when no adapter is present #8826

Merged
merged 2 commits into from
Sep 4, 2023
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
11 changes: 8 additions & 3 deletions packages/store/src/-private/store-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ class Store extends EmberObject {
// to avoid conflicts.

if (properties.id === null || properties.id === undefined) {
let adapter = this.adapterFor(modelName);
let adapter = this.adapterFor(modelName, true);

if (adapter && adapter.generateIdForRecord) {
properties.id = adapter.generateIdForRecord(this, modelName, properties);
Expand Down Expand Up @@ -2256,7 +2256,9 @@ class Store extends EmberObject {
@param {String} modelName
@return Adapter
*/
adapterFor(modelName: string) {
adapterFor(modelName: string): MinimumAdapterInterface;
adapterFor(modelName: string, _allowMissing: true): MinimumAdapterInterface | undefined;
adapterFor(modelName: string, _allowMissing?: true): MinimumAdapterInterface | undefined {
if (DEBUG) {
assertDestroyingStore(this, 'adapterFor');
}
Expand Down Expand Up @@ -2292,7 +2294,10 @@ class Store extends EmberObject {
return adapter;
}

assert(`No adapter was found for '${modelName}' and no 'application' adapter was found as a fallback.`);
assert(
`No adapter was found for '${modelName}' and no 'application' adapter was found as a fallback.`,
_allowMissing
);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/adapter-encapsulation/tests/integration/generate-id-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,22 @@ module('integration/generate-id - GenerateIdForRecord Tests', function (hooks) {

assert.deepEqual(record.serialize().data.attributes, props, 'record created without error');
});

test('store.createRecord does not error if adapter is undefined.', async function (assert) {
let store = this.owner.lookup('service:store');
let expectedData = {
data: {
type: 'person',
attributes: {
firstName: 'Gaurav',
lastName: 'Munjal',
},
},
};

let props = expectedData.data.attributes;
let record = store.createRecord('person', props);

assert.deepEqual(record.serialize().data.attributes, props, 'record created without error');
});
});
Loading