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
3.0 - Implement magic find methods on Cake\ORM\Table #2212
Comments
Yep, a must have 👍 |
How about to extract to a behavior? |
That could be possible, it will require that people opt-into magic finder methods though by adding the behavior. I've still not put much thought into how we can make adding common behaviors like timestamps more simple. I guess having base classes implement Adding the magic finders in a behavior will probably require modifying how method maps are generated for behaviors as well. You might need to enable pattern matching again, as generating all the permutations for any given table would be too expensive. |
I too am in favor of extracting the logic rather than embedding it - it's convenient for some but not all users use it (plus it's functionality that users ask to extend/modify). |
On reflection I think, if implemented, this should be in the table class. That way it's simple to implement by rewriting:
To:
Which would permit using your own finders by defining which behavior-finder xxx maps to. Also avoids the need for any kind of preg_match looping to be able to know which behavior class to call - preventing adding this feature from slowing things down even when it's not in use. |
That seems like a reasonable approach, and I like the decomposition into a basic find. |
I'll take a crack at this. |
Closing as the related pull request has been merged. |
The magic findByXXX & findAllByXXX methods currently available on
Model
are handy for doing simple queries as they expose a powerful and simple to use API.It would be nice to have the same features available on the new Cake\ORM\Table class in 3.0.
Implementation suggestions
Table
class already has a__call
method, hook into that to provide this feature.AND
anOR
operators for now, much like in 2.x.The text was updated successfully, but these errors were encountered: