Skip to content
This repository has been archived by the owner on May 28, 2021. It is now read-only.

Add option to configure a default connection in getConnection #3

Closed
stevleibelt opened this issue Jul 4, 2017 · 3 comments
Closed
Assignees
Milestone

Comments

@stevleibelt
Copy link
Member

When a class is generated, the method "getConnection" looks like the following.

    /**
     * @param null|string $name - The data source name that is used to look up the DSN from the runtime configuration file.
     * @param string $mode The connection mode (this applies to replication systems).
     * @return PDO
     */
    public function getConnection($name = null, $mode = Propel::CONNECTION_WRITE)
    {
        return Propel::getConnection($name, $mode);
    }

It can happen that you are using multiple databases resulting in multiple generated classes.
To still be able to get the right connection without passing around the name, it would be good to configure the default name. If the default name is configured, the generated method could look like that.

    /**
     * @param null|string $name - The data source name that is used to look up the DSN from the runtime configuration file.
     * @param string $mode The connection mode (this applies to replication systems).
     * @return PDO
     */
    public function getConnection($name = null, $mode = Propel::CONNECTION_WRITE)
    {
        if (is_null($name)) {
            $name = 'my_configured_default_value';
        }

        return Propel::getConnection($name, $mode);
    }

The same could be done for the value "$mode".

@stevleibelt
Copy link
Member Author

An other option would be to use the configured database name within the schema.xml as default.

$this->getDatabase()->getName().

@stevleibelt stevleibelt self-assigned this Jul 4, 2017
@stevleibelt
Copy link
Member Author

Started working on this in branch issue_2.

@stevleibelt
Copy link
Member Author

Fixed in release 1.1.0 - This is for you @alex :-).

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

No branches or pull requests

1 participant