I am trying to fetch related record with the help of pouchdb.rel.find('') it works fine when i give integer id it fetch the related data, but i don't give integer id while storing and give same id generated by couch db it is not working then
this will work
pouchdb.rel
.save('staff', {
title: 'Rails is Unagi',
text: 'Delicious unagi. Mmmmmm.',
id:5
})
.then((data) => {
console.log(data);
return pouchdb.rel.save('agent', {
description: 'nice masculine jawline',
staff: data.id
});
});
but this will not work
pouchdb.rel
.save('staff', {
title: 'Rails is Unagi',
text: 'Delicious unagi. Mmmmmm.',
})
.then((data) => {
console.log(data);
return pouchdb.rel.save('agent', {
description: 'nice masculine jawline',
staff: data.id
});
});
As i can not give id manually every time, maybe i am missing some please guide me about it what i am doing wrong here
this is full file i am working on
import PouchDB from 'pouchdb';
//import some adapter
import find from 'pouchdb-find';
import rel from 'relational-pouch';
// import { bulkStaaff } from './bulk';
PouchDB.plugin(require('pouchdb-adapter-http').default)
.plugin(require('pouchdb-authentication').default)
.plugin(require('pouchdb-adapter-indexeddb'))
.plugin(find)
.plugin(rel)
.plugin(require('pouchdb-replication'));
const remotedb = new PouchDB('http://localhost:5984/siloc');
const pouchdb = new PouchDB('siloc');
// const db = new PouchDb('http://localhost:5984/siloc');
pouchdb.setSchema([
{ singular: 'staff', plural: 'staffs', relations: { agent: { belongsTo: 'agent' } } },
{ singular: 'agent', plural: 'agents', relations: { staff: { belongsTo: 'staff' } } },
{ singular: 'ranchOwner', plural: 'ranchOwners', relations: { staff: { belongsTo: 'staff' } } },
{ singular: 'rightHandMan', plural: 'rightHandMen', relations: { staff: { belongsTo: 'staff' } } },
{ singular: 'independentContractor', plural: 'independentContractors', relations: { staff: { belongsTo: 'staff' } } },
{ singular: 'packagingCompany', plural: 'packagingCompanies', relations: { staff: { belongsTo: 'staff' } } },
{ singular: 'cuttingCompany', plural: 'cuttingCompanies', relations: { staff: { belongsTo: 'staff' } } },
{ singular: 'truck', plural: 'trucks', relations: { staff: { belongsTo: 'staff' } } },
{ singular: 'boss', plural: 'bosses', relations: { staff: { belongsTo: 'staff' } } }
]);
remotedb
.sync(pouchdb, {
live: true,
retry: true
})
.on('change', function (info) {
// handle change
console.log(info);
})
.on('paused', function (err) {
// replication paused (e.g. replication up to date, user went offline)
console.log(err);
})
.on('active', function () {
// replicate resumed (e.g. new changes replicating, user went back online)
})
.on('denied', function (err) {
// a document failed to replicate (e.g. due to permissions)
console.log(err);
})
.on('complete', function (info) {
// handle complete
console.log(info);
})
.on('error', function (err) {
// handle error
console.log(err);
});
// bulkStaaff.forEach((staff) => {
// pouchdb.rel.save('staff', staff);
// });
// pouchdb.rel
// .save('staff', {
// title: 'Rails is Unagi',
// text: 'Delicious unagi. Mmmmmm.',
// id:5
// })
// .then((data) => {
// console.log(data);
// return pouchdb.rel.save('agent', {
// description: 'nice masculine jawline',
// id: 1,
// staff: data.id
// });
// });
console.log(pouchdb.rel.find('staff','F8AD62DF-C70B-BEA3-B42F-639013CECC23'))
export { pouchdb, remotedb };