2016-08-08 1 views
2

je veux aller chercher la catégorie et les inventaires de même catégorie, je peux aller chercher l'inventaire et sa catégorie en utilisant peupler .. mais je veux inverser de lui. mais je ne sais pas comment .. j'utilise remplir la fonction, mais il ne fonctionne pasvoulez effectuer la requête de jointure dans voiles js dans l'inventaire et le modèle de catégorie (mongodb)

Modèle d'inventaire "use strict";

/** 
* Inventory 
* @description :: Model for storing Inventory records 
*/ 

module.exports = { 
    schema: true, 
    autoPk:false, 
    attributes: { 
    // Fill your attributes here 

    id: { 
     type: 'string', 
     primaryKey: true 
    }, 
    name: { 
     type: 'string' 
    }, 
    brand: { 
     type: 'string' 
    }, 
    price: { 
     type: 'float' 
    }, 
    discount: { 
     type: 'string' 
    }, 
    description: { 
     type: 'string' 
    }, 
    business: { 
     model: 'Business' 
    }, 
    images: { 
     type: 'array' 
    }, 
    quantity: { 
     type: 'integer', 
     defaultsTo: 1 
    }, 
    inStock: { 
     type: 'boolean', 
     defaultsTo: true 
    }, 
    category: { 
     model: 'Category' 
    }, 

    categoryName: { 
     type: 'string' 
    }, 

    deviceId: { 
     type: 'string' 
    }, 

    localId: { 
     type: 'string' 
    }, 

    productId: { 
     type: 'string' 
    }, 

    costPrice: { 
     type: 'float' 
    }, 

    supplierName: { 
     type: 'string' 
    }, 

    notes: { 
     type: 'array' 
    }, 

    extra: { 
     type: 'object' 
    }, 

    reviews: { 
     collection: 'Review', 
     via: 'inventory' 
    }, 

    views: { 
     type: 'integer', 
     defaultsTo: 0 
    }, 

    lastSeen: { 
     type: 'datetime', 
     defaultsTo: null 
    }, 

    toJSON() { 
     return this.toObject(); 
    } 
    }, 

    beforeUpdate: (values, next) => next(), 
    beforeCreate: (values, next) => next() 
}; 


and category model is 

"use strict"; 

/** 
* Category 
* @description :: Model for storing Category records 
*/ 

module.exports = { 
    schema: true, 
    attributes: { 
    // Fill your attributes here 
    id: { 
     primaryKey: true, 
     type: 'string' 
    }, 
    name: { 
     type: 'string' 
    }, 
    business: { 
     model: 'Business' 
    }, 

    deviceId: { 
     type: 'string' 
    }, 

    localId: { 
     type: 'string' 
    }, 
    toJSON() { 
     return this.toObject(); 
    } 
    }, 

    beforeUpdate: (values, next) => next(),`enter code here` 
    beforeCreate: (values, next) => next() 
}; 

Répondre