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

DDC-2313: Deep clone for DBAL QueryBuilder #3017

Closed
doctrinebot opened this issue Feb 21, 2013 · 5 comments
Closed

DDC-2313: Deep clone for DBAL QueryBuilder #3017

doctrinebot opened this issue Feb 21, 2013 · 5 comments
Assignees
Milestone

Comments

@doctrinebot
Copy link

Jira issue originally created by user tcm:

This is basically a duplicate of another issue I stumbled across lately but cannot find here again. It added a **clone() function to the ORM QueryBuilder to allow this use case:
Create a base query and derive two different queries from it.

I adopted the code for the DBAL QueryBuilder which is suffering the same issue (e.g. expressions were not cloned but shared between instances). The code is tested at least for my limited use case.

    /****
     * Deep clone of all expression objects in the SQL parts.
     *
     * @return void
     */
    public function **clone()
    {
        foreach ($this->sqlParts as $part => $elements) {
            if (is_array($this->sqlParts[$part])) {
                foreach ($this->sqlParts[$part] as $idx => $element) {
                    if (is_object($element)) {
                        $this->sqlParts[$part][$idx] = clone $element;
                    }
                }
            } else if (is_object($elements)) {
                $this->sqlParts[$part] = clone $elements;
            }
        }

        $params = array();

        foreach ($this->params as $param) {
            $params[] = clone $param;
        }

        $this->params = $params;
    }
@doctrinebot
Copy link
Author

@doctrinebot
Copy link
Author

Comment created by tcm:

Thanks for adding the code tags. Just updated my doctrine to 2.4-RC1 and did not find this in there. Would be nice to see this in the new version. Any obstacles I could be of help with?

@doctrinebot
Copy link
Author

Comment created by @Ocramius:

[~tcm], there's an open PR at doctrine/dbal#327

@doctrinebot
Copy link
Author

Comment created by @beberlei:

Fixed in 2.4

@doctrinebot
Copy link
Author

Issue was closed with resolution "Fixed"

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

No branches or pull requests

2 participants