strongloop

Ensure unique field value in loopback model

杀马特。学长 韩版系。学妹 提交于 2019-12-03 07:01:33
问题 How to ensure uniqueness of a particular field in loopback model. Like below is the model Post, I have a field genericId in it, I want it to be unique in the database, and loopback to through an error, on duplicate key insertion. { "name": "Post", "plural": "Post", "base": "PersistedModel", "properties": { "genericId": { "type": "string", "required":True }, "moderatedAt": { "type": "date" } }, "validations": [], "acls": [], "methods": [] } I have tried searching there documentation, and other

Auto-create mysql table with StrongLoop

六月ゝ 毕业季﹏ 提交于 2019-12-03 05:30:18
I am trying to use Strongloop with MySql but cannot figure out how to migrate or automatically create tables into a MySql database. Is there at least a way to export the models into MySql schemas or do I have to manually create the tables? I've been trying with the mysql demo app, and going over the docs for a while but no luck - http://docs.strongloop.com/display/DOC/MySQL+connector Thanks! user3259256 LoopBack calls it auto-migration. Check these links and search for that term: Recipes for LoopBack Models, part 5 of 5: Model Synchronization with Relational Databases Data sources and

Loopback discoverAndBuildModels not generating models

前提是你 提交于 2019-12-03 03:34:07
I'm trying to get Loopback to discover and build my first table. I've used the simple example on their page at the bottom here: http://docs.strongloop.com/display/LB/Database+discovery+API#DatabasediscoveryAPI-Exampleofbuildingmodelsviadiscovery and I see the output of the table I'm discovering, but the API Explorer doesn't show the table or any newly generated endpoints. Also, the model-config.js file is not updated with the new table object. Here is the basic section of the code done on server start: var loopback = require('loopback'); var boot = require('loopback-boot'); var DataSource =

StrongLoop Loopback Model find with OR condition on WHERE filter

匿名 (未验证) 提交于 2019-12-03 01:34:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to find a person by either their name OR identifier using StrongLoop's Model.find syntax (documentation here: http://apidocs.strongloop.com/loopback/#modelfindfilter-callback ). But I can't figure out how to specify the OR condition. I can match both the name AND identifier using this syntax: person.find({ where: { 'name.text': {like: 'Dave'}, 'identifier.value': {like: '3303927'} } }, callback); But I'd like to be able to match name OR identifier doing something like this: person.find({ where: { 'name.text': {like: 'Dave'} ||

Ensure unique field value in loopback model

会有一股神秘感。 提交于 2019-12-02 20:39:25
How to ensure uniqueness of a particular field in loopback model. Like below is the model Post, I have a field genericId in it, I want it to be unique in the database, and loopback to through an error, on duplicate key insertion. { "name": "Post", "plural": "Post", "base": "PersistedModel", "properties": { "genericId": { "type": "string", "required":True }, "moderatedAt": { "type": "date" } }, "validations": [], "acls": [], "methods": [] } I have tried searching there documentation, and other examples but no success. One solution which I can think of is, to create a remoteHook for the create

Constantly getting 401 errors in loopback while using User Model

烂漫一生 提交于 2019-12-02 02:12:39
问题 I am new to loopback and I am not able to extend User Base model properly. Though in explorer it shows that it is extended but all API's give a 401 error. ex. In normal get call for /users I get.. { "error": { "name": "Error", "status": 401, "message": "Authorization Required", "statusCode": 401, "code": "AUTHORIZATION_REQUIRED", "stack": "Error: Authorization Required" } } I went thru all the links and questions but none of they are working for me. I have properly put public:true in model

Access request headers from beforeSave Model Hook

本秂侑毒 提交于 2019-12-01 17:28:11
How can i access the details of the user who raise the request from a Model Hook Comment.beforeSave = function(next,com) { //Want to add 2 more properties before saving com.added_at = new Date(); com.added_by = //How can i set the user id here ?? //In case of a Remote hook i have ctx in param and i can get user id like this ctx.req.accessToken.userId; But in Model Hook how can i do the same? next(); }; Is there any way to do this? I tried with Remote hook for main Item in the way MainItem.beforeRemote('**', function(ctx, user, next) { if(ctx.methodString == 'leave_request.prototype.__create_

Access request headers from beforeSave Model Hook

陌路散爱 提交于 2019-12-01 16:53:37
问题 How can i access the details of the user who raise the request from a Model Hook Comment.beforeSave = function(next,com) { //Want to add 2 more properties before saving com.added_at = new Date(); com.added_by = //How can i set the user id here ?? //In case of a Remote hook i have ctx in param and i can get user id like this ctx.req.accessToken.userId; But in Model Hook how can i do the same? next(); }; Is there any way to do this? I tried with Remote hook for main Item in the way MainItem

Save multiple models in loopback

你离开我真会死。 提交于 2019-12-01 14:38:20
I'm doing research on loopback and was wondering if it's possible to save to multiple models from one request. Say.. an Post has many Tags with many Images. A user form would have the following: Post Title Post Description Tag Names (A multi field. E.g.: ['Sci-Fi', 'Fiction', 'BestSeller'] Image File (Hoping to process the file uploaded to AWS, maybe with skipper-s3?) How would I be able to persist on multiple models like this? Is this something you do with a hook? You can create RemoteMethods in a Model, which can define parameters, so in your example you could create something like this in

Save multiple models in loopback

为君一笑 提交于 2019-12-01 12:45:31
问题 I'm doing research on loopback and was wondering if it's possible to save to multiple models from one request. Say.. an Post has many Tags with many Images. A user form would have the following: Post Title Post Description Tag Names (A multi field. E.g.: ['Sci-Fi', 'Fiction', 'BestSeller'] Image File (Hoping to process the file uploaded to AWS, maybe with skipper-s3?) How would I be able to persist on multiple models like this? Is this something you do with a hook? 回答1: You can create