0
votes

Sails JS: Sélectionnez les enregistrements de MySQL?

J'essaie de sélectionner tous les enregistrements de table appelé Faircustomer où Business_Type_ID Équipez-vous égal de valeur. J'utilise Sailsjs pour serveur et mySQL pour dB, dans Frontend, j'utilise Nationticscript avec TypeScript.

Mon code: P>

P>

 filterShopType(){
      this.service.serviceName = 'fairCustomers';
        this.service.Get({ populate:'country_id,business_type_id',where:{ business_type_id:{ in:this.business_ids_filter } }, limit:20 }).then((data: any) => {
            this.fairCustomers.splice(0, this.fairCustomers.length);
            this.fairCustomers.push(data);
            this.Refresh('fairCustomers');
        }).catch((err) => {
            console.log('failed get fairCustomers from server ', err);
        });
    }


0 commentaires

3 Réponses :


0
votes

Vous pouvez essayer avec une requête native comme décrit ici, https://sailsjs.com/documentation/reference/waterline-orme/dataSores/send-native-Query


0 commentaires


0
votes

Cela fonctionne avec moi en utilisant [ou] au lieu de [in], il s'agit du code

p>

    filterShopType(){
        if(this.business_ids_filter){
            this.service.serviceName = 'fairCustomers';
            var arr = [];
            this.business_ids_filter.forEach( (id) => {
                arr.push({ business_type_id: id })
            });
            let where = {};
            if(arr.length > 0){
                where = {or: arr};
            }
            this.service.Get({ populate: 'country_id,business_type_id',where:where , limit:20 }).then((data: any) => {
                this.filterItems.splice(0, this.filterItems.length);
                this.filterItems.push(data);
                this.Refresh('filterItems');
            }).catch((err) => {
                console.log('failed get fair Customers from server ', err);
            });
        }else{
            this.set('isFilter', false);
        }
    }


0 commentaires