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

Make create() return the object #24

Merged
merged 5 commits into from Feb 3, 2017
Merged

Make create() return the object #24

merged 5 commits into from Feb 3, 2017

Conversation

haltcase
Copy link
Owner

@haltcase haltcase commented Feb 3, 2017

Following discussion in #21, and possibly superseding #22.

Updates the return value of create() to be the created value rather than the number of updated rows. This is a breaking change, but it makes more sense given that the number modified would always have been 0 or 1 so it might as well give you the object if 1, or nothing if 0.

If the model schema has an auto-incrementing primary key, the table is queried to find the last increment and that is used to return the object. If not, a standard primary key or unique constraint will be used. If neither of these exists in the schema the creation object itself will be used as criteria as a best-effort to return the created object.

citycide added 5 commits February 2, 2017 23:26
Change the return value of `create()` to be the newly created object, or the existing one if a unique violation was encountered.

This makes more sense given that in general the number modifed would always have been 0 or 1 so it might as well give you the object if 1, or nothing if 0.

BREAKING CHANGE: The return value of `create()` is no longer the number of created objects. Instead, `create()` returns the created object.
Stop iteration early if an auto-incrementing key is encountered. Note that iteration isn't stopped early if a unique or primary key is encountered because autoincrement should be favored.
@jonataswalker
Copy link

Just beautiful. 👍 Much better. Please merge.

@haltcase haltcase changed the title [WIP] Make create() return the object Make create() return the object Feb 3, 2017
@haltcase haltcase merged commit 3f7f662 into master Feb 3, 2017
@haltcase haltcase deleted the feat-create-return branch February 3, 2017 19:21
@haltcase
Copy link
Owner Author

haltcase commented Feb 3, 2017

This is merged to master and I'll release it next chance I get.

@jonataswalker thanks for all your help and efforts - I know we didn't merge yours but this PR was definitely driven by your work. 🥇

@haltcase haltcase added the type: feature Request for a new feature or enhancement. label Oct 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature Request for a new feature or enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants