Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
The function Model_Whatever::find_by_id_and_user_id() is apparently accessing the database via ORM to find the object with the given id and userid. My question is, does the ORM use some sort of cache so the same query executed twice will only count as one access to the database? If I use find_by_id_and_user_id() twice in the same function will it access the db twice? If so, should I just store the value as a variable so I can reuse it or is there some function in fuel that already caches these database queries?
If you use Model::find($id) it won't be fetched twice, when done like your example it will be fetched again. That is because when using find() with a primary key value it checks whether it was fetched already. But when using Model::find_by_id($id) that really means Model::query()->where('id', $id)->get(), which is just querying and those aren't checked (though a tiny bit of memory is saved after fetching from the DB during hydration, there will be only one instance in memory of the object).
Add a Comment
It looks like you're new here. If you want to get involved, click one of these buttons!
Apply for Membership
↳ Job Board
↳ Installation & Setup
↳ Tips and Tutorials
↳ Code share
In this Discussion