-
Notifications
You must be signed in to change notification settings - Fork 13
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
Foreign key that references a column that is already part of another foreign key generates invalid code #41
Labels
bug
Something isn't working
Comments
This fails: public extension SQLRecordFetchOperations
where T == Parent, Ops: SQLDatabaseFetchOperations, Ops.RecordTypes == ForeignKeys.RecordTypes
{
func find(`for` record: Child) throws -> Parent?
{
let x : SQLRecordFetchOperations<Ops, Child> = operations[dynamicMember: \.children]
return try x.findTarget(for: \.id, in: record /* Child */) // No exact matches in call to instance method 'findTarget'
}
} Maybe because of ambiguous overloads? public extension SQLRecordFetchOperations
where T == Parent, Ops: SQLDatabaseFetchOperations & SQLDatabaseAsyncOperations, Ops.RecordTypes == ForeignKeys.RecordTypes
{
func find(`for` record: Child) async throws -> Parent?
{
try await operations[dynamicMember: \.children].findTarget(for: \.id, in: record)
}
} |
Hm, no, this doesn't match is not found: public extension SQLRecordFetchOperations
where Ops: SQLDatabaseAsyncOperations
func findTarget<FK>(for foreignKey: KeyPath<T.Schema, FK>, in record: T)
async throws -> FK.Destination?
where FK: SQLForeignKeyColumn, FK.T == T,
FK.Value == FK.DestinationColumn.Value |
Just collecting data, public struct Child : Identifiable, SQLKeyedTableRecord, Codable, Sendable {
public static let schema = Schema()
public var id : Int?
public var name : String?
public init(id: Int? = nil, name: String? = nil)
}
public struct Parent : Identifiable, SQLKeyedTableRecord, Codable, Sendable {
public static let schema = Schema()
public var id : Int?
public var name : String?
public init(id: Int? = nil, name: String? = nil)
}
public struct Grandparent : Identifiable, SQLKeyedTableRecord, Codable, Sendable {
public static let schema = Schema()
public var id : Int?
public var name : String?
public init(id: Int? = nil, name: String? = nil)
} public extension Grandparent {
struct Schema : SQLKeyedTableSchema, SQLSwiftMatchableSchema, SQLCreatableSchema {
public typealias PropertyIndices = ( idx_id: Int32, idx_name: Int32 )
public typealias RecordType = Grandparent
public typealias MatchClosureType = ( Grandparent ) -> Bool
public static let externalName = "grandparent"
public static let columnCount : Int32 = 2
public static let primaryKeyColumn = MappedColumn<Grandparent, Int?>(
externalName: "id",
defaultValue: nil,
keyPath: \Grandparent.id
)
...
public let id = MappedColumn<Grandparent, Int?>(
externalName: "id",
defaultValue: nil,
keyPath: \Grandparent.id
)
public let name = MappedColumn<Grandparent, String?>(
externalName: "name",
defaultValue: nil,
keyPath: \Grandparent.name
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When you have a foreign key that references a column that is already part of a another fk the code generated to lookup the related records (
parent → children
andchild → parent
in this case) is invalid.attaching complete sample project but the SQL should be all you need to reproduce.
ForeignKeys.zip
The text was updated successfully, but these errors were encountered: