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

Assert that passed array to set a hasMany consists of records #3865

Merged
merged 1 commit into from
Oct 18, 2015
Merged

Assert that passed array to set a hasMany consists of records #3865

merged 1 commit into from
Oct 18, 2015

Conversation

pangratz
Copy link
Member

This addresses #3833

if (!isArrayLike(records)) { return false; }

return Ember.A(records).every((record) => Model.detectInstance(record) );
})());
Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure how helpful this assertion message is (considering the use case in #3833). Should I add an explicit check if a DS.PromiseObject is present in the passed array, and if so, warn that the passed array contains the result of a store.findRecord/store.queryRecord which is not supported and how it should be resolved?

Copy link
Member

Choose a reason for hiding this comment

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

I would keep the existing assertion about an array. Then add an new assertion that says something like all elements of a hasMany relationship must be instances of DS.Model but Ember Data found ${Ember.inspect(badRecord)}.

It may be enough to just test if the first object (if it exists) in the array is a DS.Model and assume that all elements in the array are likely to be of the same type.

Copy link
Member

Choose a reason for hiding this comment

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

👍 but no reason not to test all of them that i can think of

bmac added a commit that referenced this pull request Oct 18, 2015
Assert that passed array to set a hasMany consists of records
@bmac bmac merged commit f0a85fb into emberjs:master Oct 18, 2015
@bmac
Copy link
Member

bmac commented Oct 18, 2015

Thanks @pangratz

@pangratz pangratz deleted the add-better-assertion-for-hasMany branch October 20, 2015 21:08
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.

3 participants