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 for optional Int id properties to Model #104

Merged
merged 13 commits into from
Mar 19, 2019
Merged

Conversation

kilnerm
Copy link
Contributor

@kilnerm kilnerm commented Feb 27, 2019

This PR adds support for optional Integer id properties to the Model protocol.

The README has been updated accordingly.

@kilnerm kilnerm added this to the 2019.04 milestone Feb 27, 2019
@kilnerm kilnerm self-assigned this Feb 27, 2019
@kilnerm kilnerm requested a review from djones6 February 27, 2019 09:24
Copy link
Contributor

@djones6 djones6 left a comment

Choose a reason for hiding this comment

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

Code looks good, some comments on docs.

What about test coverage?

README.md Outdated

### Automatic id assignment

If your `Model` is defined without specifying an id field using the `idColumnName` property or the default name of `id` then the ORM will create an auto incrementing column named `id` in the database table for the `Model`, eg.
Copy link
Contributor

Choose a reason for hiding this comment

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

I find this sentence hard to parse. Could we add some punctuation?

README.md Outdated

### Manual id assignment

You can add an id field to your model and manage the assignment of id’s yourself by either specifying a property name for your id field using the `idColumnName` property or by defining a field named `id`, which is the default name for the aforementioned property. For example:
Copy link
Contributor

Choose a reason for hiding this comment

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

No apostrophe in "ids"

README.md Outdated

### Using `optional` id fields

If you would like an id field that allows you to specify specific values whilst also being automatic when an id is not explicitly set you can use an optional Int for your id field and re-define the `idKeypath` property to point at the field. `IDKeyPath` is a typealias for `WritableKeyPath<Self, Int?>?`, your re-definition must be explicity set this type. For example:
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs punctuation, and I think 'redefine' is not hyphenated. Also the second sentence doesn't look right - "your re-definition must be explicity set this type". Perhaps just "Your definition must be of type IDKeyPath, as in the example below". If someone really wants to know more about IDKeyPath they could look at the source.

README.md Outdated
}
```

**NOTE** - When using manual or option id fields you need to ensure that the application is written to handle violation of unique identifier constraints which will occur if you attempt to save a model with an id that already exists in the database. If you are using `SwiftKueryPostgreSQL` this error can occur when savinf with a `nil` value for the id property due to the way PostgreSQL implements `autoincrement` behaviour.
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: saving
Also, if we're going to mention Postgres' behaviour specifically, we might want to elude to why (ie. that it does not skip over existing ids while incrementing).

@kilnerm kilnerm modified the milestones: 2019.04, 2019.06 Mar 13, 2019
@djones6 djones6 self-requested a review March 19, 2019 10:58
@djones6 djones6 merged commit bbfbb38 into master Mar 19, 2019
@djones6 djones6 deleted the opt_id_keypath branch March 19, 2019 11:41
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