Skip to content

How about changing the variable name idKeypath? #122

@fummicc1

Description

@fummicc1

Suggestion. How about changing the variable name idKeypath?

Nice to meet you, I recently started studying Kitura. Thank you for your daily maintenance!
This is my personal opinion, but I would be happy if you could refer to it.

This is a quote from this site,

Using optional ID properties
Declaring your ID property as optional allows the ORM to assign the ID automatically when the model is saved. If the value of ID is nil, the database will assign an auto-incremented value. At present this is only support for an Int? type.

You may instead provide an explicit value, which will be used instead of automatic assignment.

Optional IDs must be identified by defining the idKeypath: IDKeyPath property, as in the example below:

struct Person: Model {
    var id: Int?
    var firstname: String
    var surname: String
    var age: Int

    static var idKeypath: IDKeyPath = \Person.id
}

I think the idKeypath property should be written in LowerCamelCase. What do you think?
In fact, I didn't work because I declared the idKeyPath property.

Environment Details

  • MacOS ... Catalina 10.15 beta
  • Xcode ... 10.3
  • Swift ... 5.0

Steps to Reproduce

  1. ...
    Define a structure that inherits Model, declare idKeyPath as a property, and confirm that it does not work.
  2. ...
    You will notice that it is an idKeypath property instead of an idKeyPath property, and fix the code. I think it works well.

Expected vs. Actual Behaviour

  • Expected to happen (I would like to write like this) ...
struct Diary: Equatable, Model {
    var id: Int?
    var title: String?
    
    static var idKeyPath: IDKeyPath = \Diary.id
}
  • Actually happened (current way) ...
struct Diary: Equatable, Model {
    var id: Int?
    var title: String?
    
    static var idKeypath: IDKeyPath = \Diary.id
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions