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

Granchild relationship repeats child id #13

Open
802044875 opened this issue May 16, 2023 · 0 comments
Open

Granchild relationship repeats child id #13

802044875 opened this issue May 16, 2023 · 0 comments

Comments

@802044875
Copy link

I'm getting the following run-time error:

RoutingKit/TrieRouter.swift:215: Precondition failed: It is not possible to have two routes with the same prefix but different parameter names, even if the trailing path components differ (tried to add route with clubID that collides with eventID).

I'm probably doing something stupid here. I've a parent (Club), children (Event) and grandchildren (Table) - to represent a bridge club. Here's the model:

import Fluent
import Vapor

final class Club: Model, Content {
    static let schema = "club"
    
    @ID(key: .id)
    var id: UUID?
    
    @Field(key: "name")
    var name: String
    
    @Children(for: \.$club)
    var events: [Event]
    
    init() { }
    
    init(
        id: UUID? = nil,
        name: String
    ) {
        self.id = id
        self.name = name
    }
}

final class Event: Model, Content {
    static let schema = "event"
    
    @ID(key: .id)
    var id: UUID?
    
    @Parent(key: "club_id")
    var club: Club
    
    @Field(key: "date")
    var date: Date
    
    @Children(for: \.$event)
    var tables: [Table]
    
    init() { }
    
    init(
        id: UUID? = nil,
        clubID: Club.IDValue,
        date: Date
    ) {
        self.id = id
        self.$club.id = clubID
        
        self.date = date
    }
}

final class Table: Model, Content {
    static let schema = "table"
    
    @ID(key: .id)
    var id: UUID?
    
    @Parent(key: "event_id")
    var event: Event
    
    init() { }
    
    init(
        id: UUID? = nil,
        eventID: Event.IDValue
    ) {
        self.id = id
        self.$event.id = eventID
    }
}

Heres my routes.swift:

import Fluent
import Vapor
import CrudRouter

func routes(_ app: Application) throws {
    app.crud(register: Club.self) { router in
        router.crud(children: \.$events) { router in
            router.crud(children: \.$tables)
        }
    }
    
    for route in app.routes.all {
        print(route.description)
    }
}

I'm expecting the print out of the app.routes.all to generate something like:

PUT /club/:clubID
DELETE /club/:clubID
POST /club
GET /club
GET /club/:clubID
GET /club/:clubID/event
POST /club/:clubID/event
GET /club/:clubID/event/:eventID
DELETE /club/:clubID/event/:eventID
PUT /club/:clubID/event/:eventID
POST /club/:clubID/event/:eventID/table
DELETE /club/:clubID/event/:eventID/table/:tableID
GET /club/:clubID/event/:eventID/table/:tableID
GET /club/:clubID/event/:eventID/table
PUT /club/:clubID/event/:eventID/table/:tableID

But its actually generating:

PUT /club/:clubID
DELETE /club/:clubID
POST /club
GET /club
GET /club/:clubID
GET /club/:clubID/event
POST /club/:clubID/event
GET /club/:clubID/event/:eventID
DELETE /club/:clubID/event/:eventID
PUT /club/:clubID/event/:eventID
POST /club/:clubID/event/:clubID/table
DELETE /club/:clubID/event/:clubID/table/:tableID
GET /club/:clubID/event/:clubID/table/:tableID
GET /club/:clubID/event/:clubID/table
PUT /club/:clubID/event/:clubID/table/:tableID

Where the last five routes use the clubID for the event resource.

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

No branches or pull requests

1 participant