Question

Good Morning,

why there are two methods, who returning the almost the same result.

I know "only", that the method Method.fetch() returns a promise.

What is the main difference between this two methods?

Was it helpful?

Solution

They return different results :) fetch returns a promise (as you said) immediately, which upon resolution will be your record. find returns a record immediately (possibly empty). If the record already exists client side then it will return that record, if it doesn't, it's an empty record, and once ember model finishes fetching the data it will populate the record with it's properties. They both have their pros/cons. fetch is safer for async programming if you depend on the record being populated before using it. find is convenient for immediate response time, with delayed population. Click run inside the examples a few times to view the differences.

Find

http://jsbin.com/UXOtOJI/20/edit

Fetch

http://jsbin.com/porozuno/1/edit

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top