-
Notifications
You must be signed in to change notification settings - Fork 30
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
Conversation
There was a problem hiding this 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. |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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).
This PR adds support for optional Integer
id
properties to theModel
protocol.The README has been updated accordingly.