-
Notifications
You must be signed in to change notification settings - Fork 440
Feature/Discussion: Scopes #306
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
base: master
Are you sure you want to change the base?
Conversation
…ugs related to delagating to finder methods, Added more tests to test more extravagant cases
…removed Variables added to Model and placed them within the scope of the Scope instance, eliminating the need to use an object instance
…eing called and not being used for anything fancy
I really like this idea/implementation. Maybe the API could be a little cleaner, but I love the idea of chaining scope calls. I'd love to hear what others have to say. |
In my opinion, scopes aren't just a feature to php-activerecord, it's a necessity and many people are waiting for this for long time (me included). But it's not a simple thing to implement. When I wrote the first lines it was to supply my own needs and I decided pushing here to boost the idea. Thanks @anther for keeping the job and I really expect the idea grow up and become a merged code (after revising and discuss, of course). |
I can see an improvement would be to update the API to allow |
I like @anther's current suggestion. It's introducing a brand new feature and breaking an API to build scopes into the current contract, but ppl should be able to opt-in to the feature until it becomes the standard... Perhaps in 2.0? |
It looks like chaining two scopes that do a join will only use the last join. I'm guessing they aren't being appended like the where clauses. I'll try hacking in some support for multiple joins if I can. The feature is looking good though, serving me well 👍 |
@gsterjov Completely an oversight and it makes sense for joins to be appended. Glad the rest of it is working well for you though :). @al-the-x Is the breaking of the contract adding the static scoped() method? So are you saying that it'd make sense to add a configuration option such as 'use_scopes'=>true, and then at that point the check for the usage of scopes. |
@anther Yes, that's what I was referring to. The |
What about having the joins resolve itself much like how the 'joins' option currently does? |
As an update, I noticed that I would frequently call scopes with
So I added the
It can now be replaced with the following and have minimal chance of breaking previous code... *kind of!
You can then simply do
* |
…how where already works, in this particular case for appending joins to each other, additional tests will follow
I haven't been keeping up with this at all. What's the stability like? Have you had any problems with this feature in your fork? |
*/ | ||
public static function scoped() | ||
{ | ||
require_once(__DIR__.'/Scope.php'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using an include/require statement here seems dirty. Could we move it?
I like the concept of chaining conditions, but I don't like the What if we add Book::where(['author' => 'Some Name']); // => returns a Scope
Book::where(['author' => 'Some Name'])->order(['publication_year' => '2013']); // => returns a Scope Methods in
Where |
I think this doesn't handle scoped I found the problem in OptionBinder.php inside the
|
I want to start a discussion on adding scopes to PHPActiveRecord!
This is a branch that I started working on earlier this year after discovering GH-252 by @CarlosBonetti. He began work on what I thought was a very good idea but a pretty rough implementation of scoping features. I've been tweaking and adding to it to the point that I've used this implementation on several live web-apps and feel that this would add a lot of value to PHPActiveRecord and be very nice to not only have in my home version ;p.
I've since updated his code to have a much smoother and slightly less intrusive interface with pre-existing phpactiverecord code. I've also put some checks in place so that it currently won't override any behavior of previous code if scopes are not used at all, thus in theory all previous code behaves the same.
There are still some rough edge cases in the implementation right now but they're all relatively easy to iron out, as rough edges tend to be :p.
I'm going to pull these examples from code we currently have active. I'm also pretty sure the majority of you know what scopes are and how they work but here's an example of this particular implementation in practice.
I really want input and some other programmer talents to jump into this because I feel it's very close to being ready to integrate fully and after some scrutiny this can possibly even be added as a feature to the current active build (As it's backwards compatible at the moment).
What do you guys think??