1
我試圖把它關閉儘可能長,但我真的被困在這裏。CouchbaseLite逆向關係不起作用
基本上我的計劃是這樣的:
class Album
var artist: artist?
class Artist
@NSManaged var albums:NSArray?
class func albumsInverseRelation() -> String { return "artist" }
class func albumsItemClass() -> AnyClass { return Album.self }
再後來我嘗試訪問的計算性能,albums
bgdb.modelFactory?.registerClass("Album", forDocumentType: "Album")
bgdb.modelFactory?.registerClass("Artist", forDocumentType: "Artist")
if let artistID = artist?.document?.documentID, let fetchedArtist = try! Artist.fetchOne(field: "_id", operand: .Matches, value: artistID as AnyObject, database: bgdb) {
print(fetchedArtist.albums as! [Album])
}
但fetchedArtist.albums
回報一個空陣列!
這就是爲什麼我很困惑,從調試:
(lldb) po album?.artist?.document?.documentID
▿ Optional<String>
- some : "-obO5dJTBF-xu4lzbWTM9yU"
(lldb) po fetchedArtist.document?.documentID
▿ Optional<String>
- some : "-obO5dJTBF-xu4lzbWTM9yU"
由於它的出現,有一個相冊有一個藝術家ID ,我也可以匹配藝術家ID與現有的藝術家
然而,當我問artist
實例是albums
,它未能恢復具有相同artist
ID
我在這裏失去了一些東西的專輯?