node.js - node orm hasone relationship -
i'm trying use simple hasone relationship node orm module:
var shop = db.define('shops', { id: { type: "serial", key: true }, name: string }); var offer = db.define('offers', { id: { type: "serial", key: true }, name: string }); offer.hasone('shop', shop);
then shop of selected offer; in doc written hasone relationship sets new method, getshop in case:
offer.find(1, function (err, firstoffer) { if (err) throw err; firstoffer.getshop(function(err, shop) { res.send(shop); }); });
but crashes saying firstoffer has no method 'getshop'... can explain i'm doing wrong?
i think confusing find get. please change code (note in first line):
offer.get(1, function (err, firstoffer) { if (err) throw err; firstoffer.getshop(function(err, shop) { res.send(shop); }); });
when find returns array (it can return empty array), calling getshop array.
Comments
Post a Comment