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

Move sequence value methods to Model level #24292

Merged
merged 1 commit into from
Mar 24, 2016

Conversation

arthurnn
Copy link
Member

Summary

prefetch_primary_key? and next_sequence_value methods live in the
connection level at the moment, that make sense when you are generating
the sequence from the database, in the same connection. Which is the use
case today at the Oracle and Postgres adapters.
However if you have an service that generates IDs, that has nothing to
do with the database connection, and should not be fetched from there.
Another use case, is if you want to use another connection to fetch IDs,
that would not be possible with the current implementation, however when
we move those methods to the model level, you can use a new connection
there.

Also this makes easier for gems to add behavior on those methods.

review @jeremy @sgrif @rafaelfranca
cc @jesseplusplus

@rafaelfranca
Copy link
Member

Also this makes easier for gems to add behavior on those methods.

If we plan to make these things extention points to gems and applications we should remove the # :nodoc: comment otherwise they would be private API and we could move/remove without warning. Also we should probably document.

Other than that I'm fine with this change.

@arthurnn
Copy link
Member Author

If we plan to make these things extention points to gems and applications we should remove the # :nodoc: comment otherwise they would be private API and we could move/remove without warning. Also we should probably document.

I agree, I was not sure tho if we wanted to make this not private right at the first iteration. But It make sense.. I will document those methods.

@arthurnn
Copy link
Member Author

@rafaelfranca added the comments.

@@ -231,6 +231,19 @@ def sequence_name=(value)
@explicit_sequence_name = true
end

# Should primary key values be selected from their corresponding
Copy link
Member

Choose a reason for hiding this comment

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

# Determines if the primary key values should be selected from their corresponding sequence before the insert statement.

`prefetch_primary_key?` and `next_sequence_value` methods live in the
connection level at the moment, that make sense when you are generating
the sequence from the database, in the same connection. Which is the use
case today at the Oracle and Postgres adapters.
However if you have an service that generates IDs, that has nothing to
do with the database connection, and should not be fetched from there.
Another use case, is if you want to use another connection to fetch IDs,
that would not be possible with the current implementation, however when
we move those methods to the model level, you can use a new connection
there.

Also this makes easier for gems to add behavior on those methods.
@arthurnn
Copy link
Member Author

@rafaelfranca docs updated. Thanks for the review

@arthurnn arthurnn merged commit a12ad8a into rails:master Mar 24, 2016
@arthurnn arthurnn deleted the arthurnn/pk_sequence_klass branch March 24, 2016 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants