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

Created method called after fetch #124

Closed
wants to merge 3 commits into from

Conversation

stekycz
Copy link
Contributor

@stekycz stekycz commented Aug 17, 2014

preLoad: It is useful to filter data by complex conditions in relatively simple query and then use it it data loading (main) query.
postLoad: It is useful to load some extra relations which could negatively affect performance if it would be included in main query.

It can be used in following way

class ComplexQuery extends QueryObject
{
    private $ids = array();

    protected function doCreateQuery(Queryable $repository)
    {
        // process query which loads only @...ToOne relations
    }

    public function preFetch(Queryable $repository, $limit = NULL, $offset = NULL)
    {
        // process filtering of main entity IDs
        $this->ids = $ids;
    }

    public function postFetch(Queryable $repository, \Iterator $iterator)
    {
        $result = iterator_to_array($iterator, TRUE);
        // process loading of all needed relations in @...ToMany direction
    }
}

It is useful to load some extra relations which could negatively affect performance if it would be included in main query.
* @param \Iterator $iterator
* @return void
*/
public function doAfterFetch(Queryable $repository, \Iterator $iterator)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that onAfterFetch() would be better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to postFetch to be compatible with Doctrine naming. It is also shorter :-)

@fprochazka fprochazka force-pushed the master branch 2 times, most recently from f935e4d to aff77eb Compare February 2, 2015 01:54
fprochazka pushed a commit that referenced this pull request Feb 12, 2015
It is useful to load some extra relations which could negatively affect performance if it would be included in main query.
@fprochazka
Copy link
Member

@stekycz I've merged the postFetch. I'm not sure how the preFetch should work and what is the use-case. I might have a use-case in mind, but such api would be insufficient for it.

@fprochazka fprochazka closed this Feb 12, 2015
@fprochazka
Copy link
Member

Thank you :)

@stekycz stekycz deleted the feature/after-fetch branch February 12, 2015 08:46
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

Successfully merging this pull request may close these issues.

2 participants