jugglingdb

Compound JS Relationship Access

北城以北 提交于 2020-01-04 05:48:08
问题 I have defined 2 schema objects as below (for use in a mongodb) var User = describe('User', function () { property('name', String); property('email', String); property('password', String); set('restPath', pathTo.users); }); var Message = describe('Message', function () { property('userId', String, { index : true }); property('content', String); property('timesent', Date, { default : Date }); property('channelid', String); set('restPath', pathTo.messages); }); Message.belongsTo(User, {as:

Loopback 2.4: how to query certain fields of related model via REST API

家住魔仙堡 提交于 2019-12-07 04:03:53
问题 I have User model over relational DB. Each User can hasMany "users" where "chiefId" is FK. "relations": { "users": { "type": "hasMany", "model": "User", "foreignKey": "chiefId" }, } I can query related users for each chief-user like this: GET /users?filter={"include":"users"} But it returns full user objects. How should I query only "name" properties of related users? Also is it possible to count related instances in one request to server? 回答1: A late reply but I just ran into this question