read() vs find()

What exactly is the differednce between $this->User->read() and $this->User->find()?

Seemingly, they both retrieve the data (and possibly associated data) for the User model. Yet, there is a an important distinction: read() will also set the data for your model object, while find() will simply return the resultset array.

What’s the big deal?
None, really. However, if you are not planning to manipulate the object in any way, what exactly is the point of populating it with any data?
If your goal is simply to get some data and pass it to the view for display, you should stick with using find(). As a matter of fact read() will call find() internally anyways.

That beings said, read() can probably be useful if you need to manipulate your model’s data and then save it. Surely the same can be done with find(), but read() will provide a cleaner syntax, if that’s what you are after.

I’m not going to address any issues with performance, because if you are running into bottlenecks due to the performance of read() vs find(), I’m sure you’ve got more pressing issues at hand to deal with (like saving your DB or purchasing a better server).

Related Posts