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

Add support \Phalcon\Mvc\Model::selectWriteConnection #1519

Merged
merged 1 commit into from
Nov 11, 2013
Merged

Add support \Phalcon\Mvc\Model::selectWriteConnection #1519

merged 1 commit into from
Nov 11, 2013

Conversation

dreamsxin
Copy link
Contributor

class Robots extends Phalcon\Mvc\Model
{
    /**
     * Dynamically selects a shard
     *
     * @param array $intermediate
     * @param array $bindParams
     * @param array $bindTypes
     */
    public function selectWriteConnection($intermediate, $bindParams, $bindTypes)
    {
        //Check if there is a 'where' clause in the select
        if (isset($intermediate['where'])) {

            $conditions = $intermediate['where'];

            //Choose the possible shard according to the conditions
            if ($conditions['left']['name'] == 'id') {
                $id = $conditions['right']['value'];
                if ($id > 0 && $id < 10000) {
                    return $this->getDI()->get('dbShard1');
                }
                if ($id > 10000) {
                    return $this->getDI()->get('dbShard2');
                }
            }
        }

        //Use a default shard
        return $this->getDI()->get('dbShard0');
    }

}

@phalcon
Copy link
Collaborator

phalcon commented Nov 8, 2013

Which database supports this kind of writing?

@dreamsxin
Copy link
Contributor Author

@phalcon
Phalcon read transverse slices, writing should also support, practical application, we may according to the user ID, the resulting data is written to the specified database.

phalcon pushed a commit that referenced this pull request Nov 11, 2013
Add support \Phalcon\Mvc\Model::selectWriteConnection
@phalcon phalcon merged commit c24994c into phalcon:1.3.0 Nov 11, 2013
@phalcon
Copy link
Collaborator

phalcon commented Nov 11, 2013

Could you please port this to 2.0.0?

@dreamsxin dreamsxin deleted the selectWriteConnection branch August 20, 2014 08:00
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