Use $$links since it will eventually be part of PouchORM
This commit is contained in:
parent
8cfb7f575e
commit
e29e41514a
@ -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);
|
||||||
|
|||||||
@ -3,13 +3,17 @@ import { pouchDocHash, deepAssign } from './utils.js';
|
|||||||
export class TypeSpec {
|
export class TypeSpec {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
this._populateId(props);
|
this._populateId(props);
|
||||||
Object.assign(this, { $links: {} }, props, { type: this._prefix });
|
Object.assign(this, { $$links: {} }, props, { $$type: this._prefix });
|
||||||
}
|
}
|
||||||
|
|
||||||
static getUniqueID(doc) {
|
static getUniqueID(doc) {
|
||||||
throw 'NotImplemented';
|
throw 'NotImplemented';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static isType(doc) {
|
||||||
|
return doc && doc.$$type === TypeSpec.prefix;
|
||||||
|
}
|
||||||
|
|
||||||
static validate(doc) {}
|
static validate(doc) {}
|
||||||
|
|
||||||
instantiate(doc) {
|
instantiate(doc) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user