Skip to content

Conversation

@taoso
Copy link
Contributor

@taoso taoso commented Dec 11, 2014

Eloquent use the read pdo for select query.

However, in some scenes, it needs to query data just from the write pdo(master db), because of the delay of database syncing.

As @crynobone says(#6599), the demand can be satisfied by the use of User::on('mysql::write')->find(1);. But, in my opinion, using the on method is not a natural way. Because every Eloquent model knows which db connection they will use. There should be no need to use the on method to set a concrete connection name.

Here is my solution. I add a new onWrite method to the Eloquent. We could do:

$user = User::onWrite()->find(1);

@taoso taoso changed the title Select from write pdo [4.2] Select from write pdo Dec 12, 2014
@taoso taoso changed the title [4.2] Select from write pdo [4.2] Database: Select from write pdo Dec 12, 2014
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please put braces on their own lines.

@GrahamCampbell
Copy link
Collaborator

Please fix the inline issues, then squash to one commit.

@GrahamCampbell GrahamCampbell changed the title [4.2] Database: Select from write pdo [4.2] Select From Write Pdo Dec 13, 2014
@taoso
Copy link
Contributor Author

taoso commented Dec 15, 2014

@GrahamCampbell sorry for troubles. And coding style has been adjusted at eb9d915

Copy link
Contributor

Choose a reason for hiding this comment

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

Need docblock

taylorotwell added a commit that referenced this pull request Dec 15, 2014
@taylorotwell taylorotwell merged commit 9161736 into laravel:4.2 Dec 15, 2014
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.

4 participants