Custom validation errors gets set multiple times

Issue I created a custom validation for one of my models properties the following way: Model.validateAsync(‘minOsVersion’, validateMinimumOsVersion, {message: ‘Minimum OS Version incorrect’}); function validateMinimumOsVersion(err, done) { var requiredVersion = “some version”; var givenVersion = this.minOsVersion; if (validator.validateSemanticVersionString(givenVersion, requiredVersion) < 0)

Continue reading

How to order the GET response using loopback

Issue I’ve a simple model which looks something like this: { “name”: “reason”, “plural”: “reasons”, “base”: “PersistedModel”, “idInjection”: true, “options”: { “validateUpsert”: true }, “properties”: { “title”: { “type”: “string”, “required”: true }, “position”: { “type”: “number”, “required”: true }

Continue reading

Promisfy loopback models

Issue In unit testing Loopback it is necessary to use callbacks with the upsert methods. So for example … instead of writing something along the lines of this: before(function () { Student = server.models.Student Course = server.models.Course Course.upsert({id: 1, key:

Continue reading

Loopback Download file

Issue I am following the document for download the file. https://docs.strongloop.com/display/public/LB/Storage+component In that document if download the file means need to follow the url pattern. GET /containers/{container}/files/{file} Example: I have container1 (container name), and file name lb.png. So I maked

Continue reading

loopback include with two models

Issue This current code is working : app.models.AvionPiloteAutorisation.find({ “where”: { “idAvion”: avion.idAvion }, “include”: [“pilote”] }, function(err, pilotes) { … } But this : app.models.AvionPiloteAutorisation.find({ “filter”: { “where”: { “idAvion”: avion.idAvion }, “include”: { “relation”: “pilote” } } }) fail.

Continue reading

Loopback android sdk fields are null

Issue I have class Item which extends from Model with annotations ORMLite @DatabaseTable public class Item extends Model { @DatabaseField(id = true) public String id; @DatabaseField public String title; @DatabaseField public String details; @DatabaseField public String phone; @DatabaseField(defaultValue = “1000”)

Continue reading

Loopback update model after save

Issue I want to update last inserted/updated document(row) in “after save” hook without create new instance of that like this: Model.observe(‘after save’, function (ctx, next) { ctx.someProperty = ‘Foo’; ctx.update(); }); How it possible? Solution I’m not sure what you

Continue reading

Is it possible to remove an operation hook?

Issue Let say I have bind an operation hook for test purpose like the following: it(‘verification link confirms mail’,function(done){ var client = app.models.client; client.observe(‘after save’, function(ctx, next) { if (!ctx.instance.verificationToken){ next(); return; } var link = ‘/api/clients/confirm?uid=’ + ctx.instance.id +

Continue reading

Operation hook for hasAndBelongsToMany

Issue How can I configure an operation hook, such as after save, when linking or unlinking an instance of the foreign model? Using loopback’s example Assembly and Part model: https://docs.strongloop.com/display/public/LB/HasAndBelongsToMany+relations I would like to execute code when adding (or removing)

Continue reading

StrongLoop: ACL for Subtable

Issue I have two tables A and B. A hasOne B, B belongsTo A. Now I have the following ACL in B: { “principalType”: “ROLE”, “principalId”: “$everyone”, “permission”: “DENY”, “accessType”: “*” } When I make a request to localhost/api/B/{id} I

Continue reading

loopback-storage-component how to display picture – file

Issue I am using loopback-component-storage for uploading images to server. https://docs.strongloop.com/display/public/LB/Storage+component I have also AngularJS JavaScript SDK so my lb-services.js is dynamically updated. https://docs.strongloop.com/display/public/LB/AngularJS+JavaScript+SDK Now I want to display in my webpage the photo from this loopback component storage model,

Continue reading

Double many-to-many relationship

Issue In loopback I have defined two models with a double many-to-many relationship as follows: action.json: { “name”: “Action”, “base”: “PersistedModel”, “idInjection”: true, “options”: { “validateUpsert”: true }, “properties”: { “text”: { “type”: “string”, “required”: true } }, “validations”: [],

Continue reading

Loopback data denormalization

Issue I have 2 models. One is an Article (content, category), and the other is Category (id, name). In Article I have defined relation to Category. “categories”: { “type”: “hasOne”, “model”: “Category”, “foreignKey”: “category” } I insert new Product with

Continue reading

Nested Models in Loopback Android SDK

Issue I have a loopback instance with MongoDB backend, and have defined a model that has a nested (anonymous) model called ‘location’ as a property: “name”: “thing”, “plural”: “things”, “base”: “PersistedModel”, “idInjection”: true, “options”: { “validateUpsert”: true }, “properties”: {

Continue reading

What's the difference between Loopback's operation hooks vs events?

Issue Loopback seems to have overlapping concepts when handling certain points of time in an model’s lifecycle: https://docs.strongloop.com/display/public/LB/Operation+hooks Applied through Model.observe vs https://docs.strongloop.com/display/public/LB/Events#Events-Modelevents Applied through Model.on Both seem to have similar ways of handling CRUD events. What’s the difference between

Continue reading

Apply disableRemoteMethod for a lot of models

Issue How I can apply this to all my models? common/models/task.js module.exports = function(Task) { Task.disableRemoteMethod(“upsert”, true); Task.disableRemoteMethod(“updateAll”, true); Task.disableRemoteMethod(“updateAttributes”, false); Task.disableRemoteMethod(‘createChangeStream’, true); Task.disableRemoteMethod(“find”, true); Task.disableRemoteMethod(“replaceOrCreate”, true); }; For example, for Project, User etc. Solution Create a mixin and disable

Continue reading

StrongLoop modify data before each get on model

Issue I have the following model in LoopBackJS: { “name”: “member”, “base”: “PersistedModel”, “properties”: { “firstName”: { “type”: “string” } “public”: { “type”: “boolean” } }, “relations”: { “spouse”: { “type”: “hasOne”, “model”: “spouse”, “foreignKey”: “spouseId” } } } Now

Continue reading