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) {
|
||||
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);
|
||||
|
||||
@ -3,13 +3,17 @@ import { pouchDocHash, deepAssign } from './utils.js';
|
||||
export class TypeSpec {
|
||||
constructor(props) {
|
||||
this._populateId(props);
|
||||
Object.assign(this, { $links: {} }, props, { type: this._prefix });
|
||||
Object.assign(this, { $$links: {} }, props, { $$type: this._prefix });
|
||||
}
|
||||
|
||||
static getUniqueID(doc) {
|
||||
throw 'NotImplemented';
|
||||
}
|
||||
|
||||
static isType(doc) {
|
||||
return doc && doc.$$type === TypeSpec.prefix;
|
||||
}
|
||||
|
||||
static validate(doc) {}
|
||||
|
||||
instantiate(doc) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user