strongloop / loopback

LoopBack makes it easy to build modern applications that require complex integrations.
http://loopback.io
Other
13.22k stars 1.2k forks source link

nestRemoting a remote method ? #2378

Closed shalkam closed 8 years ago

shalkam commented 8 years ago

Hi, I'd like to know if there is a way to do the nestRemoting on a model's remote method. I am using the paginate mixin : https://github.com/fullcube/loopback-ds-paginate-mixin for a client model

client.json

{
  "name": "client",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "id": {
      "type": "number"
    },
    "name": {
      "type": "string",
      "required": true
    },
    "type": {
      "type": "string",
      "required": true
    },
    "coords": {
      "type": "geopoint"
    },
    "address": {
      "type": "string",
      "required": true
    },
    "tel": {
      "type": "string",
      "required": true
    },
    "areaid": {
      "type": "number",
      "required": true
    },
    "subareaid": {
      "type": "number",
      "required": true
    },
    "pobox": {
      "type": "string"
    }
  },
  "validations": [
  ],
  "relations": {
    "pharmacistsRel": {
      "type": "embedsMany",
      "model": "pharmacist",
      "property": "pharmacists"
    },
    "doctorsRel": {
      "type": "embedsMany",
      "model": "doctor",
      "property": "doctors"
    },
    "area": {
      "type": "belongsTo",
      "model": "Area",
      "foreignKey": "areaid"
    },
    "subarea": {
      "type": "belongsTo",
      "model": "Subarea",
      "foreignKey": "subareaid"
    },
    "users": {
      "type": "hasMany",
      "model": "user",
      "foreignKey": "clientid",
      "through": "userClient"
    },
    "visits": {
      "type": "hasMany",
      "model": "visit",
      "foreignKey": "clientid"
    }
  },
  "acls": [
  ],
  "methods": {},
  "mixins": {
    "Paginate": {
      "limit": "10"
    }
  }
}

client.js

module.exports = function (Client) {
    Client.nestRemoting('Paginate');
};

and of course the app crashed with an error

Error: Relation `Paginate` does not exist for model `client`

regards, Mostafa

0candy commented 8 years ago

nestRemoting is for querying a nested model while you're using paginate to paginate an existing model. You won't be able to query the paginate tool.

shalkam commented 8 years ago

what about a remote method defined according the documentation here : https://docs.strongloop.com/display/public/LB/Remote+methods

I guess it's not supported too in loopback.

0candy commented 8 years ago

Why are you querying the mixin in the model? What are you trying to do?

shalkam commented 8 years ago

I've been able to take care of my problem without having to use the mixin for pagaination. I am just saying that there will be cases where remote methods should be nested too just like the case with the relations of the related model.

0candy commented 8 years ago

@shalkam Since you were able to take care of your issue, I am closing this. Thanks!