pomm-project / ModelManager

Model Manager for the Pomm database framework.
MIT License
66 stars 27 forks source link

Added a findOneWhere() method which greatly simplifies fetching resul… #62

Closed crxgames closed 7 years ago

crxgames commented 8 years ago

Added a findOneWhere() method which greatly simplifies the processing of fetching results where one single result is being fetched via a where statement. This reduces code required to check the iterator in whatever project is using the library.

Example: $userobj = $pomm->getModel(PublicSchema\UsersModel::class)->findOneWhere('username = $*', [$_POST['username']]);

chanmix51 commented 8 years ago

Thank you for the PR. I cannot merge it directly into 2.0 branch because this is the actual stable branch and it is bug / security fix only. Moreover, the PR comes with no tests and has commented lines in it.

This said, I will add it in current master that will become 2.1. If you want to use this feature in your current developments using Pomm 2.0, you should create your own query trait that implements your findOneWhere method and use it in your model classes.

chanmix51 commented 8 years ago

In order I add a feature request, is it possible you give me some use cases this method would be needed ?

chanmix51 commented 7 years ago

The findOneWhere method is not very consistent because it can return a single row from a query that returns several ones. The updateWhere is a good idea but the proposed implementation does not offer the capability to pass SQL expressions (ie … SET column = function()). Since there are no tests committed with this PR, it can not be merged.