Skip to content
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

Allow to pass filters in ClassMethods constructor #6

Open
bakura10 opened this issue Jun 28, 2014 · 0 comments
Open

Allow to pass filters in ClassMethods constructor #6

bakura10 opened this issue Jun 28, 2014 · 0 comments

Comments

@bakura10
Copy link
Member

After using this prototype's philosophy and never extending ClassMethods but rather composing it, I feel that this is actually a nice idea. However there is one caveat: https://github.com/zf-fr/hydrator#why-built-in-hydrators-are-final-and-how-should-i-use-them

Because we cannot modify the filters defined in ClassMethods for instance, the only way we have to filter properties is to use unset. Not really a problem, with one exception. Imagine you have an entity:

class Foo
{
    protected $coll;

    public function getActiveMembersCount()
    {
        return $coll->matching(Criteria::expr(Criteria::eq('active', true)));
    }
}

Of course, we could use the hydrator to unset the "active_members_count" property if we don't want it, BUT it generated a useless SQL query that is indeed not needed by the extraction method of the hydrator.

What I suggest is allowing to pass a specific filter to ClassMethods constructor, so it leaves the chance to add filters (like ExcludeMethods one) that get appended to the filter chain. We still have the performance benefits as this can be set only in the constructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant