I've been reading the loobpack's framework documentation but I couldn't find the answer I need.
I would like to know if there is any options to set a property as case insensitive in the database.
I know I can handle this in the front-end of the application, however front-end validations are extremely dangerous as they can be overrided.
I currently have a model with the following content on myModel.json:
{
"name": "mymodel",
"properties": {
"id": {
"type": "number",
"required": true
},
"code": {
"type": "string",
"required": true,
"index": {
"unique": true
}
},
"name": {
"type": "string",
"required": true
},
}
}
The property code has to be unique, however I've tried to insert the word "COD001" and "cod001" and they were both accepted.
You could use the 'check uniqueness' validation method.
MyModel.validatesUniquenessOf('code', {ignoreCase: false});
Reference: https://apidocs.loopback.io/loopback-datasource-juggler/#validatable-validatesuniquenessof
Related
I have recently started working on strapi and was looking at the relations inside model in their documentation. My scenario is as follows. I have a model named course and another named tag. They have many to many relationship between them.This is what ./api/course/models/course.settings.json has when I made the relation between them named as tag2.
{
"connection": "default",
"collectionName": "course",
"info": {
"name": "course"
},
"options": {
"increments": true,
"timestamps": true
},
"attributes": {
"image_link": {
"type": "string"
},
"created_by": {
"columnName": "created_by_id",
"plugin": "users-permissions",
"model": "user"
},
"updated_by": {
"columnName": "updated_by_id",
"plugin": "users-permissions",
"model": "user"
},
"title": {
"type": "string"
},
"short_description": {
"type": "text"
},
"slug": {
"type": "string",
"unique": true
},
"tags2": {
"collection": "tag",
"via": "courses",
"dominant": true
}
}
}
When I specify the relation using the admin panel strapi itself made a junction table named as courses_tags_2_s__tags_courses.
Here is what tag model looks like
{
"connection": "default",
"collectionName": "tag",
"info": {
"name": "tag",
"mainField": "ui_label"
},
"options": {
"increments": true,
"timestamps": true
},
"attributes": {
"code": {
"type": "string"
},
"description": {
"type": "string"
},
"created_by": {
"plugin": "users-permissions",
"model": "user",
"columnName": "created_by_id"
},
"updated_by": {
"plugin": "users-permissions",
"model": "user",
"columnName": "updated_by_id"
},
"ui_label": {
"type": "string"
},
"courses": {
"via": "tags2",
"collection": "course"
}
}
}
I have a couple of questions
1) Is there a way I can set up the junction table as courses_tags ? i.e overriding the strapi one
2) I have set my mainField as "ui_label" in tag.settings.json but in the admin panel while editing course table content(rows in course table), in the related field of tag2 I see "code" field shown there instead of "ui_label". How to set the mainField?
Note: I have setup strapi with mysql server.
so to answer your first question, there is currently no way to override the join table between two models. This is totally auto-generated by Strapi.
For the second question, this part of the docs is out to date.
To manage display information you will have to use the content manager configuration in the admin panel.
Here a short video - https://www.youtube.com/watch?v=tzipS2CePRc&list=PL7Q0DQYATmvhlHxHqfKHsr-zFls2mIVTi&index=5&t=0s
For 1) Is there a way I can set up the junction table as courses_tags ? i.e overriding the strapi one:
You can specify the following option:
"collectionName": "courses_tags"
I'm trying to create a generic CSV dataset with parametrized filename and schema to be able to use it in foreach loops with file lists and I'm having some trouble on publishing, and I don't know if I'm doing something wrong or if the framework docs are not correct.
According to documentation the schema description is:
Columns that define the physical type schema of the dataset. Type: array (or Expression with resultType array), itemType: DatasetSchemaDataElement.
I have a dataset with a parameter named Schema of type Array and the "schema" set to an expression that returns this parameter:
{
"name": "GenericCSVFile",
"properties": {
"linkedServiceName": {
"referenceName": "LinkedServiceReferenceName",
"type": "LinkedServiceReference"
},
"parameters": {
"Schema": {
"type": "array"
},
"TableName": {
"type": "string"
},
"TableSchema": {
"type": "string"
}
},
"folder": {
"name": "Folder"
},
"type": "DelimitedText",
"typeProperties": {
"location": {
"type": "AzureDataLakeStoreLocation",
"fileName": {
"value": "#concat(dataset().TableSchema,'.',dataset().TableName,'.csv')",
"type": "Expression"
},
"folderPath": "Path"
},
"columnDelimiter": ",",
"escapeChar": "\\",
"firstRowAsHeader": true,
"quoteChar": "\""
},
"schema": {
"value": "#dataset().Schema",
"type": "Expression"
}
},
"type": "Microsoft.DataFactory/factories/datasets"
}
However, when I publish, i get the following error:
Error code: BadRequest
Inner error code: InvalidPropertyValue
Message: Invalid value for property 'schema'
Am I doing something wrong? are the docs wrong?
Yes, this is the expected behavior. If you need to set dynamic value for column mapping, please ignore schema in DelimitedText dataset, which is more for a visually display of physical schema information and would not take effect when do copy activity column mapping. The expression setting for it is also not allowed. You could configure mapping as an expression to achieve this goal and pass it a proper value when trigger run.
I was trying to add JSON schema validation with in a Logic App using ParseJSON action.
I want to validate the existence of either of the object in the message (equivalent to XSD choice).
For instance, messages may have either of lastname or familyname.
{
"name": "Alan",
"familyname": "Turing"
}
Or
{
"name": "Alan",
"lastname": "Turing"
}
I modified the generated schema as,
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"oneOf": [
{
"lastname": {
"type": "string"
}
},
{
"familyname": {
"type": "string"
}
}
]
}
}
Logic App execution throws below error
Just to test if any other schema combination keywords works, tried to test with anyOf in place of oneOf and it fails in execution as well.
Does Logic Apps support these extended validation ? Am I missing some specific syntax here ?
If you are validating that either familyname or lastname be present then you are missing the "required" attribute.
{
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"oneOf": [
{
"familyname": {
"type": "string"
},
"required": [ "familyname" ]
},
{
"lastname": {
"type": "string"
},
"required": [ "lastname" ]
}
]
}
This will validate the JSON. If you want to get the values out in a later step you could use the coalesce function.
#coalesce(actionBody('Parse_JSON')?['familyname'], actionBody('Parse_JSON')?['lastname'])
In my mongodb i have several arrays, but when i load those arrays from the database they strangley are objects instead of arrays.
This strange behaviour is since a couple of days, before everything worked fine and i got arrays out of the database.
Has loopback some strange flags which are set automatically, that transform my arrays to objects or something like that?
Currently I have the newest versions in all my packages and have already tried to use older versions, but nothing changes this behaviour.
At first there was also a problem with the saving of the arrays, sometimes they were saved as objects, but since I removed all null objects from the database, only arrays were saved.
The problem occurs with the sections array
my model json is:
{
"name": "Track",
"plural": "Tracks",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"alreadySynced": {
"type": "boolean"
},
"approved": {
"type": "boolean"
},
"deletedByClient": {
"type": "boolean",
"default": false
},
"sections": {
"type": "object",
"required": true
},
"type": {
"type": "string"
},
"email": {
"type": "string",
"default": ""
},
"name": {
"type": "string",
"default": "Neuer Track"
},
"reason": {
"type": "string",
"default": ""
},
"date": {
"type": "date"
},
"duration": {
"type": "number",
"default": 0
},
"correctnessscore": {
"type": "number",
"default": 0
},
"evaluation": {
"type": "object"
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
I have also already tried to change the type object to array but without success
Well, I am not seeing any array type in your model and I am not sure what is exactly your problem.
Has loopback some strange flags which are set automatically, that
transform my arrays to objects or something like that?
No loopback has no flags and doesn't transform any data type unless you set it !
So if you define a property as object and you are passing an array without validating the data type this will change the type of your data and save it as object instead of array.
Lets define an array in your Track model :
"property": {
"type": "array"
}
Do you need array of objects?
"property": {
"type": ["object"]
}
Strings ?
"property": {
"type": ["string"]
}
Numbers ?
"property": {
"type": ["number"]
}
Read more about loopback types here.
I have been trying to get the addSiteAccount1 API endpoint to accept the data I am sending it.
According to the documentation I have set out the structure below.
The first structure I tried used an array for the current credentialsField object, but I couldn't set "enclosedType" of the credentialFields array... so that was scrapped in favour of an object with numbered keys.
{
"cobSessionToken": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"userSessionToken": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"siteId": 4252,
"credentialFields": {
"0": {
"displayName": "Customer Number(DOB (ddmmyy) followed by unique number)",
"fieldType": {
"typeName": "IF_LOGIN"
},
"name": "LOGIN",
"valueMask": "LOGIN_FIELD",
"isEditable": true,
"valueIdentifier": "LOGIN",
"value": "123456789"
},
"1": {
"displayName": "Security Number",
"fieldType": {
"typeName": "IF_PASSWORD"
},
"name": "PASSWORD",
"valueMask": "LOGIN_FIELD",
"isEditable": true,
"valueIdentifier": "PASSWORD",
"value": "123456789"
},
"2": {
"displayName": "Password",
"fieldType": {
"typeName": "IF_PASSWORD"
},
"name": "PASSWORD1",
"valueMask": "LOGIN_FIELD",
"isEditable": true,
"valueIdentifier": "PASSWORD1",
"value": "password123"
},
"enclosedType": "com.yodlee.common.FieldInfoSingle"
}
}
Unfortunately, I only ever get the following response from Yodlee, which hasn't helped very much. If anyone can see where I'm going wrong it would be much appreciated.
{
"errorOccurred": "true",
"exceptionType": "Exception Occurred",
"referenceCode": "_f2d54a4c-f328-418e-b9fd-cec0be18f5e1"
}
Thanks in advance.
You are facing the same problem as this post , please see the answer and follow it.