@@ -88,7 +88,7 @@ import Foundation
88
88
/// directly by host applications. The behavior of this may change without warning.
89
89
public enum ModelAssociation {
90
90
case hasMany( associatedFieldName: String ? , associatedFieldNames: [ String ] = [ ] )
91
- case hasOne( associatedFieldName: String ? , targetNames: [ String ] )
91
+ case hasOne( associatedFieldName: String ? , associatedFieldNames : [ String ] = [ ] , targetNames: [ String ] )
92
92
case belongsTo( associatedFieldName: String ? , targetNames: [ String ] )
93
93
94
94
public static let belongsTo : ModelAssociation = . belongsTo( associatedFieldName: nil , targetNames: [ ] )
@@ -108,14 +108,20 @@ public enum ModelAssociation {
108
108
)
109
109
}
110
110
111
- @available ( * , deprecated, message: " Use hasOne(associatedWith:targetNames:) " )
111
+ @available ( * , deprecated, message: " Use hasOne(associatedWith:associatedFields: targetNames:) " )
112
112
public static func hasOne( associatedWith: CodingKey ? , targetName: String ? = nil ) -> ModelAssociation {
113
113
let targetNames = targetName. map { [ $0] } ?? [ ]
114
114
return . hasOne( associatedWith: associatedWith, targetNames: targetNames)
115
115
}
116
116
117
- public static func hasOne( associatedWith: CodingKey ? , targetNames: [ String ] = [ ] ) -> ModelAssociation {
118
- return . hasOne( associatedFieldName: associatedWith? . stringValue, targetNames: targetNames)
117
+ public static func hasOne(
118
+ associatedWith: CodingKey ? = nil ,
119
+ associatedFields: [ CodingKey ] = [ ] ,
120
+ targetNames: [ String ] = [ ] ) -> ModelAssociation {
121
+ return . hasOne(
122
+ associatedFieldName: associatedWith? . stringValue,
123
+ associatedFieldNames: associatedFields. map { $0. stringValue } ,
124
+ targetNames: targetNames)
119
125
}
120
126
121
127
@available ( * , deprecated, message: " Use belongsTo(associatedWith:targetNames:) " )
@@ -254,7 +260,7 @@ extension ModelField {
254
260
let associatedModel = requiredAssociatedModelName
255
261
switch association {
256
262
case . belongsTo( let associatedKey, _) ,
257
- . hasOne( let associatedKey, _) ,
263
+ . hasOne( let associatedKey, _, _ ) ,
258
264
. hasMany( let associatedKey, _) :
259
265
// TODO handle modelName casing (convert to camelCase)
260
266
let key = associatedKey ?? associatedModel
0 commit comments