Use $$links since it will eventually be part of PouchORM
This commit is contained in:
parent
9e001e862b
commit
791bf10984
@ -14,15 +14,15 @@ class AlbumSpec extends TypeSpec {
|
|||||||
|
|
||||||
async findImages(live = false) {
|
async findImages(live = false) {
|
||||||
return await ImageType.find(
|
return await ImageType.find(
|
||||||
Object.assign({ [`$links.${this._id}`]: { $exists: true } }, ImageType.selector),
|
Object.assign({ [`$$links.${this._id}`]: { $exists: true } }, ImageType.selector),
|
||||||
live
|
live
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async addImage(image) {
|
async addImage(image) {
|
||||||
if (!image.$links[this._id]) {
|
if (!image.$$links[this._id]) {
|
||||||
await image.update({
|
await image.update({
|
||||||
$links: {
|
$$links: {
|
||||||
[this._id]: {
|
[this._id]: {
|
||||||
sequence: this.count
|
sequence: this.count
|
||||||
}
|
}
|
||||||
@ -35,8 +35,8 @@ class AlbumSpec extends TypeSpec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async removeImage(image) {
|
async removeImage(image) {
|
||||||
if (image.$links[this._id]) {
|
if (image.$$links[this._id]) {
|
||||||
delete image.$links[this._id];
|
delete image.$$links[this._id];
|
||||||
this.count -= 1;
|
this.count -= 1;
|
||||||
await image.save();
|
await image.save();
|
||||||
await this.save();
|
await this.save();
|
||||||
@ -75,7 +75,7 @@ ImageType.subscribe((id, deleted, doc) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.keys(doc.$links)
|
Object.keys(doc.$$links)
|
||||||
.filter(k => k.startsWith(AlbumType.prefix))
|
.filter(k => k.startsWith(AlbumType.prefix))
|
||||||
.forEach(async albumId => {
|
.forEach(async albumId => {
|
||||||
const album = await AlbumType.find(albumId);
|
const album = await AlbumType.find(albumId);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user