Use $$links since it will eventually be part of PouchORM

This commit is contained in:
Timothy Farrell 2018-05-23 05:03:06 -05:00
parent 9e001e862b
commit 791bf10984

View File

@ -14,15 +14,15 @@ class AlbumSpec extends TypeSpec {
async findImages(live = false) {
return await ImageType.find(
Object.assign({ [`$links.${this._id}`]: { $exists: true } }, ImageType.selector),
Object.assign({ [`$$links.${this._id}`]: { $exists: true } }, ImageType.selector),
live
);
}
async addImage(image) {
if (!image.$links[this._id]) {
if (!image.$$links[this._id]) {
await image.update({
$links: {
$$links: {
[this._id]: {
sequence: this.count
}
@ -35,8 +35,8 @@ class AlbumSpec extends TypeSpec {
}
async removeImage(image) {
if (image.$links[this._id]) {
delete image.$links[this._id];
if (image.$$links[this._id]) {
delete image.$$links[this._id];
this.count -= 1;
await image.save();
await this.save();
@ -75,7 +75,7 @@ ImageType.subscribe((id, deleted, doc) => {
return;
}
Object.keys(doc.$links)
Object.keys(doc.$$links)
.filter(k => k.startsWith(AlbumType.prefix))
.forEach(async albumId => {
const album = await AlbumType.find(albumId);