I have a webshop based on React with a Loopback rest api. Now i want to add new columns to the client Table. If i add the object as property option to the client.js the error shows "Unknown column 'gender_delivery' in 'field list'". See the image below. The comments are not included in the saved code.
{
"name": "client",
"plural": "clients",
"base": "User",
"idInjection": true,
"options": {
"allowEternalTokens": true,
"validateUpsert": true
},
"ttl": 43200,
"mixins": {
"DisableAllMethods": {
"hide": [
"prototype.__create__orders",
"prototype.__delete__orders",
"prototype.__destroyById__orders",
"prototype.__updateById__orders",
"prototype.__count__cart",
"prototype.__create__cart",
"prototype.__destroy__cart",
"prototype.__update__cart",
"prototype.__destroyById__cart",
"prototype.__findById__cart",
"prototype.__addArticle__cart",
"prototype.__updateById___cart",
"prototype.__addArticles__cart",
"reset"
]
},
"TimeStamp": {
"createdAt": "created_at",
"updatedAt": "updated_at",
"required": false,
"validateUpsert": true,
"silenceWarnings": false
}
},
"restrictResetPasswordTokenScope": true,
"emailVerificationRequired": true,
"hidden": [
"password",
"verificationToken",
"securityQuestion",
"securityQuestion",
"verificationHash"
],
"properties": {
"id": {
"type": "number",
"id": true,
"generated": true,
"mysql": {
"columnName": "id",
"dataType": "int",
"dataLength": null,
"dataPrecision": 11,
"dataScale": 0,
"nullable": "N"
}
},
"oid": {
"type": "number"
},
"username": {
"type": "string",
"required": true
},
"password": {
"type": "string",
"required": true
},
"disable": {
"type": "boolean",
"required": true,
"default": false
},
"name": {
"type": "string"
},
"first_name": {
"type": "string",
"required": true
},
"middle_name": {
"type": "string"
},
"last_name": {
"type": "string",
"required": true
},
"street": {
"type": "string",
"required": true
},
"city": {
"type": "string",
"required": true
},
"telephone": {
"type": "string"
},
"fax": {
"type": "string"
},
"email": {
"type": "string",
"required": true
},
"deleted": {
"type": "boolean",
"required": true,
"default": false
},
"title": {
"type": "string"
},
"zip": {
"type": "string",
"required": true
},
"country": {
"type": "string",
"required": true
},
"company": {
"type": "string"
},
"lastlogin": {
"type": "number"
},
"is_online": {
"type": "boolean",
"required": true,
"default": false
},
"password_orig": {
"type": "string"
},
"gender": {
"type": "number"
},
"telephone2": {
"type": "string"
},
"iscompany": {
"type": "number"
},
"companyid": {
"type": "string"
},
"houseno": {
"type": "string"
},
"addressadditional": {
"type": "string"
},
"tax": {
"type": "boolean",
"required": true,
"default": true
},
"tax_type": {
"type": "number"
},
"securityQuestion": {
"type": "string",
"required": true
},
"securityAnswer": {
"type": "string",
"required": true
},
"verificationHash": {
"type": "string"
},
"showTutorial": {
"type": "boolean",
"default": true
},
// NEW COLUMNS
"gender_delivery": {
"type": "number"
},
"first_name_delivery": {
"type": "string",
"required": true
},
"last_name_delivery": {
"type": "string",
"required": true
},
"addressadditional_delivery": {
"type": "string"
},
"street_delivery": {
"type": "string",
"required": true
},
"houseno_delivery": {
"type": "string"
},
"zip_delivery": {
"type": "string",
"required": true
},
"city_delivery": {
"type": "string",
"required": true
},
"country_delivery": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {
"cart": {
"type": "hasOne",
"model": "cart",
"foreignKey": "clientId",
"primaryKey": "id"
},
"addresses": {
"type": "hasMany",
"model": "address",
"foreignKey": "clientId",
"options": {
"nestRemoting": true
}
},
"orders": {
"type": "hasMany",
"model": "order",
"foreignKey": "clientId",
"options": {
"nestRemoting": true
}
},
"projects": {
"type": "hasMany",
"model": "project",
"foreignKey": "clientId",
"options": {
"nestRemoting": true
}
}
},
"acls": [
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "create"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "deleteById"
},
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "login"
},
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "logout"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "findById"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "patchAttributes"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "replaceById"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "verify"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "verifyAccount"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "clearPassword"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "changePasswordPublic"
},
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "confirm"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "resetPassword"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW",
"property": "changePassword"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW",
"property": "setPassword"
},
{
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW",
"property": "deleteById"
},
{
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW",
"property": "exists"
},
{
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW",
"property": "find"
},
{
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW",
"property": "findById"
},
{
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW",
"property": "upsert"
},
{
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW",
"property": "updateAll"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "updateClientAttributes"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__findById__accessTokens"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__count__cart"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__create__cart"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__delete__cart"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__destroyById__cart"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__findById__cart"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__get__cart"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__addArticle__cart"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__updateById___cart"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__addArticles__cart"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__count__addresses"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__create__addresses"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__delete__addresses"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__destroyById__addresses"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__findById__addresses"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__get__addresses"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__updateById__addresses"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__count__orders"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__create__orders"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__delete__orders"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__destroyById__orders"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__findById__orders"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__get__orders"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__updateById__orders"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__createPdf__orders"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__count__projects"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__create__projects"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__delete__projects"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__destroyById__projects"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__findById__projects"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__get__projects"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__updateById__projects"
}
],
"methods": {}
}
The weird thing is that whenever i do the same with another Table it works perfectly fine. See example generas.
{
"name": "genera",
"plural": "generas",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"mixins": {
"IgnoreDeleted": true,
"RowCounter": true,
"TimeStamp": {
"createdAt": "created_at",
"updatedAt": "updated_at",
"required": false,
"validateUpsert": true,
"silenceWarnings": false
}
},
"properties": {
"id": {
"type": "number",
"id": true,
"generated": true,
"mysql": {
"columnName": "id",
"dataType": "int",
"dataLength": null,
"dataPrecision": 11,
"dataScale": 0,
"nullable": "N"
}
},
// SEE EXAMPLE TEST
"TEST": {
"type": "number"
},
"oid": {
"type": "number",
"required": false
},
"lang": {
"type": "number",
"required": true
},
"name1": {
"type": "string",
"required": true
},
"name2": {
"type": "string",
"required": true
},
"deleted": {
"type": "boolean",
"required": true,
"default": false
},
"hidden": {
"type": "boolean",
"required": true,
"default": false
},
"sortscount": {
"type": "number",
"required": true
}
},
"validations": [],
"relations": {
"categories": {
"type": "hasMany",
"model": "genera_category",
"foreignKey": "generaId",
"through": "generas_categories_mm",
"options": {
"nestRemoting": true
}
},
"arts": {
"type": "hasMany",
"model": "art",
"foreignKey": "generaId",
"options": {
"nestRemoting": true
}
},
"sorts": {
"type": "hasMany",
"model": "sort",
"foreignKey": "generaId",
"options": {
"nestRemoting": true
}
}
},
"methods": {}
}
In Addition i've tried runing yarn update tables. This command doesn't run either. It says. Cannot read 'connector' of undefined.
Here is the code inside my drop-tables.js
/* jshint esversion: 6 */
/* jshint node: true */
'use strict';
const server = require('../server/server');
const ds = server.dataSources.mySqlIds;
const models = require('../server/model-config.json');
const tables = [];
const keys = Object.keys(models);
keys.forEach(key => {
const model = models[key];
if (key[0] !== '_' && model.dataSource ===
'mySqlIds') {
tables.push(key);
}
});
const dropTablePromises = [];
console.log(tables);
tables.map(table => {
const dropTable = new Promise(function(resolve,
reject) {
ds.connector.dropTable(
table, function(err, data) {
if (err) {
reject(err);
} else {
console.log(`\tDrop table "${table}".`);
resolve({name: table, data: data});
}
});
});
dropTablePromises.push(dropTable);
});
console.log('1. DROP TABLES');
Promise.all(dropTablePromises)
.catch(err => console.log(err))
.then(() => ds.disconnect());
The result of server.dataSources is an empty object = {}
that explains why it says 'ds' is undefined. (It doesn't work with datasources either).
My goal is just to extend the clients table by a few properties.
Thank you!
I am having two models : user and car
user acl :
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW",
"property": "find"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "login"
},
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW"
}
car acl :
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "find"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
},
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
},
{
"accessType": "WRITE",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
},
{
"accessType": "WRITE",
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW"
}
I am able to add car using api /cars but unable to get list of cars using api /cars , during get it is returning AUTHORIZATION_REQUIRED error code.
note : i am logged in as a user then i am trying to get list of cars owned by user.
It's possible that you're missing to add the model relation in agreement with Loopback documentation:
To qualify a $owner, the target model needs to have a belongsTo relation
to the User model (or a model extends from User) and property matching
the foreign key of the target model instance. The check for $owner is
only performed for a remote method that has ‘:id’ on the path, for
example, GET /api/users/:id.
Also I believe it would be a good idea change the default setting aclErrorStatus from 401 to 403. This way it would be easier to understand if it's an issue with authentication or authorization.