Unable to extract value from the Response in Postman - postman

I want to extract id value from the following response body.
[
{
"id": "6311ebc04318ce16bedd1a14",
"creationMethod": "board-creation",
"name": "workspace18669413",
"credits": [],
"displayName": "Prashant Vadher's workspace",
"desc": "",
"descData": {
"emoji": {}
},
"domainName": "epam.com",
"idBoards": [],
"idEnterprise": null,
"idMemberCreator": "6310461591394a03d2012ca3",
"invited": false,
"invitations": [],
"limits": {
"orgs": {
"totalMembersPerOrg": {
"status": "ok",
"disableAt": 4000,
"warnAt": 3200
},
"freeBoardsPerOrg": {
"status": "ok",
"disableAt": 10,
"warnAt": 3
}
}
},
"memberships": [
{
"idMember": "6310461591394a03d2012ca3",
"memberType": "admin",
"unconfirmed": false,
"deactivated": false,
"id": "6311ebc04318ce16bedd1a16"
}
],
"membersCount": 1,
"prefs": {
"permissionLevel": "private",
"orgInviteRestrict": [],
"boardInviteRestrict": "any",
"externalMembersDisabled": false,
"associatedDomain": null,
"googleAppsVersion": 1,
"boardVisibilityRestrict": {
"private": "org",
"org": "org",
"enterprise": "org",
"public": "org"
},
"boardDeleteRestrict": {
"private": "org",
"org": "org",
"enterprise": "org",
"public": "org"
},
"attachmentRestrictions": null
},
"powerUps": [],
"products": [],
"billableMemberCount": 1,
"activeBillableMemberCount": 1,
"billableCollaboratorCount": 0,
"url": "https://trello.com/workspace18669413",
"website": null,
"logoHash": null,
"logoUrl": null,
"premiumFeatures": [
"additionalBoardBackgrounds",
"additionalStickers",
"customBoardBackgrounds",
"customEmoji",
"customStickers",
"plugins"
],
"promotions": [],
"enterpriseJoinRequest": {},
"standardVariation": null,
"availableLicenseCount": null,
"maximumLicenseCount": null,
"ixUpdate": null,
"teamType": null,
"canEditDomain": true
},
{
"id": "6310461e34b26a003d4f65d9",
"creationMethod": null,
"name": "userworkspace78017157",
"credits": [],
"displayName": "Trello Workspace",
"desc": "",
"descData": {
"emoji": {}
},
"domainName": "epam.com",
"idBoards": [
"6311d55c9640b1010ee3a9e6",
"6311e8216b6cd7003e656e5c",
"6311ec42e22f75004513983e",
"6311f1b3b36e0c007e68ccbb"
],
"idEnterprise": null,
"idMemberCreator": "6310461591394a03d2012ca3",
"invited": false,
"invitations": [],
"limits": {
"orgs": {
"totalMembersPerOrg": {
"status": "ok",
"disableAt": 4000,
"warnAt": 3200
},
"freeBoardsPerOrg": {
"status": "warn",
"disableAt": 10,
"warnAt": 3,
"count": 3
}
}
},
"memberships": [
{
"idMember": "6310461591394a03d2012ca3",
"memberType": "admin",
"unconfirmed": false,
"deactivated": false,
"id": "6310461e34b26a003d4f65db"
}
],
"membersCount": 1,
"prefs": {
"permissionLevel": "private",
"orgInviteRestrict": [],
"boardInviteRestrict": "any",
"externalMembersDisabled": false,
"associatedDomain": null,
"googleAppsVersion": 1,
"boardVisibilityRestrict": {
"private": "org",
"org": "org",
"enterprise": "org",
"public": "org"
},
"boardDeleteRestrict": {
"private": "org",
"org": "org",
"enterprise": "org",
"public": "org"
},
"attachmentRestrictions": null
},
"powerUps": [],
"products": [],
"billableMemberCount": 1,
"activeBillableMemberCount": 1,
"billableCollaboratorCount": 0,
"url": "https://trello.com/userworkspace78017157",
"website": null,
"logoHash": null,
"logoUrl": null,
"premiumFeatures": [
"additionalBoardBackgrounds",
"additionalStickers",
"customBoardBackgrounds",
"customEmoji",
"customStickers",
"plugins"
],
"promotions": [],
"enterpriseJoinRequest": {},
"standardVariation": null,
"availableLicenseCount": null,
"maximumLicenseCount": null,
"ixUpdate": "6",
"teamType": null,
"canEditDomain": true
}
]
I have tried following code:
*jsonData = JSON.parse(responseBody)
console.log("JSON Body - " + JSON.stringify(jsonData))
pm.environment.set('idOrganization', JSON.stringify(jsonData.id))
console.log("idOrganization: " + JSON.stringify(jsonData.id))*
But getting undefined value in console.
idOrganization: undefined
Is there any other way to save this value in environment variable ?

could you try such:
const responseJson = pm.response.json();
pm.environment.set("idOrganization", responseJson[0]["id"]);
this is for the first item from your array.

Guess your requirement is unclear, there are two id's present, which one you want to retrieve? If any specific it is already answered.
If you want both with comma separated, then please try this.
const responseBODY = pm.response.json();
let idValue = "";
for (let i=0; i < responseBODY.length; i++) {
idValue += responseBODY[i].id+",";
}
finalIDValue = idValue.substring(0,idValue.length - 1);
//put your logic how you want to use it
pm.environment.set("idOrganization", finalIDValue);

Related

AWS EventBridge Rule pattern "anything-but" with "prefix"

I'm trying to setup an AWS EventBridge rule that will filter all Okta user events with rawUserAgent as "anything-but" with the "prefix" libwww-perl. My question is that is there a way to chain AWS rule syntax on the same field in the event? I tried something like this, but it didn't work -
{
"detail": {
"eventType": [{
"prefix": "user.session.start"
}],
"outcome": {
"result": [{
"prefix": "FAILURE"
}]
},
"client": {
"userAgent": {
"rawUserAgent": [{
"anything-but": [{"prefix": "libwww-perl"}]
}]
}
}
}
}
Any suggestions on how I can achieve this?
Here's a sample event:
{
"version": "0",
"id": "123",
"detail-type": "SystemLog",
"source": "okta",
"account": "123",
"time": "2022-06-24T13:07:02Z",
"region": "us-east-1",
"resources": [],
"detail": {
"uuid": "123",
"published": "2022-06-24T13:07:02.586Z",
"eventType": "user.session.start",
"version": "0",
"displayMessage": "User login to Okta",
"severity": "INFO",
"client": {
"userAgent": {
"rawUserAgent": "libwww-perl/6.15",
"os": "Unknown",
"browser": "UNKNOWN"
},
"zone": "null",
"device": "Unknown",
"id": null,
"ipAddress": "192.168.1.1",
"geographicalContext": {
"city": null,
"state": null,
"country": "United States",
"postalCode": null,
"geolocation": {
"lat": 37.751,
"lon": -97.822
}
},
"ipChain": [
{
"ip": "192.168.1.1.",
"geographicalContext": {
"city": null,
"state": null
"country": "Canada",
"postalCode": null,
"geolocation": {
"lat": 37.751,
"lon": -97.822
}
},
"version": "V4",
"source": null
}
]
},
"device": null,
"actor": {
"id": "unknown",
"type": "User",
"alternateId": "abc#gmail.com",
"displayName": "unknown",
"detailEntry": null
},
"outcome": {
"result": "FAILURE",
"reason": "VERIFICATION_ERROR"
},
"target": null,
"transaction": {
"type": "WEB",
"id": "YrW29nCfOE-MgiNf6-1UkQAAA8I",
"detail": {}
},
"debugContext": {
"debugData": {
"loginResult": "VERIFICATION_ERROR",
"requestId": "abcd",
"threatSuspected": "true",
"requestUri": "",
"url": ""
}
},
"legacyEventType": "core.user_auth.login_failed",
"authenticationContext": {
"authenticationProvider": null,
"credentialProvider": null,
"credentialType": null,
"issuer": null,
"authenticationStep": 0,
"externalSessionId": "unknown",
"interface": null
},
"securityContext": {
"asNumber": 11174,
"asOrg": "qwerty",
"isp": "qwerty",
"domain": "qwerty.com",
"isProxy": false
},
"insertionTimestamp": null
}
}
You can use this pattern:
{
"detail": {
"eventType": [{
"prefix": "user.session.start"
}],
"client": {
"userAgent": {
"rawUserAgent": [{
"anything-but": {
"prefix": "libwww-perl"
}
}]
}
},
"outcome": {
"result": [{
"prefix": "FAILURE"
}]
}
}
}

using mongodb case insentive regex with case insentive index

is mongo regex ignoring my index? I have a case insentive index, but by the look of things my regex search recognize it and ignores it.
db.getCollection("myCol").find({ value: /^mysearchVal/i }}).explain(...)
I have 95, 708 docs total.
output:
{
"queryPlanner": {
"plannerVersion": 1,
"namespace": "myDb.myCol",
"indexFilterSet": false,
"parsedQuery": {
"Value": {
"$regex": "^mysearchVal",
"$options": "i"
}
},
"winningPlan": {
"stage": "FETCH",
"filter": {
"Value": {
"$regex": "^mysearchVal",
"$options": "i"
}
},
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"Value": 1
},
"indexName": "value_case_insensitive_and_unique",
"collation": {
"locale": "en",
"caseLevel": false,
"caseFirst": "off",
"strength": 2,
"numericOrdering": false,
"alternate": "non-ignorable",
"maxVariable": "punct",
"normalization": false,
"backwards": false,
"version": "57.1"
},
"isMultiKey": false,
"multiKeyPaths": {
"Value": []
},
"isUnique": true,
"isSparse": false,
"isPartial": false,
"indexVersion": 2,
"direction": "forward",
"indexBounds": {
"Value": [
"[\"\", {})",
"[/^mysearchVal/i, /^mysearchVal/i]"
]
}
}
},
"rejectedPlans": []
},
"executionStats": {
"executionSuccess": true,
"nReturned": 1,
"executionTimeMillis": 1447,
"totalKeysExamined": 95708,
"totalDocsExamined": 95708,
"executionStages": {
"stage": "FETCH",
"filter": {
"Value": {
"$regex": "^mysearchVal",
"$options": "i"
}
},
"nReturned": 1,
"executionTimeMillisEstimate": 1270,
"works": 95709,
"advanced": 1,
"needTime": 95707,
"needYield": 0,
"saveState": 785,
"restoreState": 785,
"isEOF": 1,
"invalidates": 0,
"docsExamined": 95708,
"alreadyHasObj": 0,
"inputStage": {
"stage": "IXSCAN",
"nReturned": 95708,
"executionTimeMillisEstimate": 596,
"works": 95709,
"advanced": 95708,
"needTime": 0,
"needYield": 0,
"saveState": 785,
"restoreState": 785,
"isEOF": 1,
"invalidates": 0,
"keyPattern": {
"Value": 1
},
"indexName": "value_case_insensitive_and_unique",
"collation": {
"locale": "en",
"caseLevel": false,
"caseFirst": "off",
"strength": 2,
"numericOrdering": false,
"alternate": "non-ignorable",
"maxVariable": "punct",
"normalization": false,
"backwards": false,
"version": "57.1"
},
"isMultiKey": false,
"multiKeyPaths": {
"Value": []
},
"isUnique": true,
"isSparse": false,
"isPartial": false,
"indexVersion": 2,
"direction": "forward",
"indexBounds": {
"Value": [
"[\"\", {})",
"[/^mysearchVal/i, /^mysearchVal/i]"
]
},
"keysExamined": 95708,
"seeks": 1,
"dupsTested": 0,
"dupsDropped": 0,
"seenInvalidated": 0
}
},
"allPlansExecution": []
},
"ok": 1.0
}
the output shows 95,708 keys and docs examined, 1 doc returned. really? did the index apply in this case or am I missing a point or two?
Case insensitive regular expression queries generally cannot use
indexes effectively. The $regex implementation is not collation-aware
and is unable to utilize case-insensitive indexes.
https://docs.mongodb.com/manual/reference/operator/query/regex/#index-use

NaN userId while setting userContext loopback

I have a model UserB2b extended from User. I have enabled authorization using server.authEnabled in the boot script so that all requests pass through the auth middleware.
Problem: Whenever I have an non-numeric username in my UserB2b model, I get a NaN userId from AccessToken.findForRequest in loopback/common/model/access-token.js.
Here are my models.
AccessToken
{
"name": "AccessToken",
"base": "AccessToken",
"idInjection": false,
"options": {
"validateUpsert": true
},
"mysql": {
"table": "AccessToken"
},
"properties": {
"ttl": {
"type": "Number",
"required": false,
"length": null,
"precision": 10,
"scale": 0,
"mysql": {
"columnName": "ttl",
"dataType": "int",
"dataLength": null,
"dataPrecision": 10,
"dataScale": 0,
"nullable": "Y"
},
"_selectable": true
},
"created": {
"type": "Date",
"required": false,
"length": null,
"precision": null,
"scale": null,
"mysql": {
"columnName": "created",
"dataType": "datetime",
"dataLength": null,
"dataPrecision": null,
"dataScale": null,
"nullable": "Y"
},
"_selectable": true
},
"userId": {
"type": "String",
"required": false,
"length": null,
"precision": 10,
"scale": 0,
"mysql": {
"columnName": "userId",
"dataType": "varchar",
"dataLength": null,
"dataPrecision": 10,
"dataScale": 0,
"nullable": "Y"
},
"_selectable": true
},
"id": {
"type": "String",
"id": true,
"required": false,
"length": 255,
"precision": null,
"scale": null,
"mysql": {
"columnName": "id",
"dataType": "varchar",
"dataLength": 255,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
},
"model": {
"type": "string",
"id": false,
"length": 100,
"precision": null,
"scale": null,
"mysql": {
"columnName": "model",
"dataType": "varchar",
"dataLength": 100,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
}
},
"validations": [],
"relations": {
"userB2B":{
"type":"belongsTo",
"model":"UserB2b",
"foreignKey":"userId"
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId":"$authenticated",
"permission": "ALLOW"
}
],
"methods": {}
}
UserB2b
{
"name": "UserB2b",
"base": "User",
"idInjection": false,
"options": {
"validateUpsert": true
},
"mysql": {
"table": "user_b2b"
},
"scope": {
"where": {
"deleted": 0
}
},
"properties": {
"username": {
"type": "String",
"id": true,
"required": true,
"length": 255,
"precision": null,
"scale": null,
"mysql": {
"columnName": "username",
"dataType": "varchar",
"dataLength": 255,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
},
"password": {
"type": "String",
"required": true,
"length": 1000,
"precision": null,
"scale": null,
"mysql": {
"columnName": "password",
"dataType": "varchar",
"dataLength": 1000,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
},
"name": {
"type": "String",
"required": true,
"length": 255,
"precision": null,
"scale": null,
"mysql": {
"columnName": "name",
"dataType": "varchar",
"dataLength": 255,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
},
"contactNumber": {
"type": "String",
"required": true,
"length": 255,
"precision": null,
"scale": null,
"mysql": {
"columnName": "contact_number",
"dataType": "varchar",
"dataLength": 255,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
},
"createdAt": {
"type": "Date",
"required": false,
"length": null,
"precision": null,
"scale": null,
"mysql": {
"columnName": "created_at",
"dataType": "timestamp",
"dataLength": null,
"dataPrecision": null,
"dataScale": null,
"nullable": "Y"
},
"_selectable": true
},
"updatedAt": {
"type": "Date",
"required": false,
"length": null,
"precision": null,
"scale": null,
"mysql": {
"columnName": "updated_at",
"dataType": "timestamp",
"dataLength": null,
"dataPrecision": null,
"dataScale": null,
"nullable": "Y"
},
"_selectable": true
},
"deleted": {
"type": "Number",
"required": false,
"length": null,
"precision": 3,
"scale": 0,
"mysql": {
"columnName": "deleted",
"dataType": "tinyint",
"dataLength": null,
"dataPrecision": 3,
"dataScale": 0,
"nullable": "Y"
},
"_selectable": true
},
"email": false,
"created": false,
"lastUpdated": false,
"credentials": false,
"challenges": false,
"status": false,
"verificationToken": false,
"realm": false,
"emailVerified": false
},
"validations": [],
"relations": {
"accessTokens": {
"type": "hasMany",
"model": "Accesstoken",
"foreignKey": "userName"
}
},
"methods": {}
}
Here is the raw packet that I get from the debugger
<-- RowDataPacket
RowDataPacket {
id: 'BJVqc7CtRXzPVVtTyJqmUabijgLRRHBe3sqcCh0bh5NuGBIZCnY8nwLIGeB6dILv',
ttl: 12096000,
created: Tue May 24 2016 05:44:18 GMT+0000 (UTC),
model: 'UserB2b',
userId: 'max1' }
and the query that loopback fires after that is
SELECT `username`,`password`,`name`,`contact_number`,`created_at`,`updated_at`,`deleted` FROM `user_b2b` WHERE (`username`=?) AND (`deleted`=?) ORDER BY `username` LIMIT 1, params: ["NaN",0]
Is there something that needs to be corrected here ?
it seems something wrong here in your access token:
"userId": {
"type": "String",
"required": false,
"length": null,
"precision": 10,
"scale": 0,
"mysql": {
"columnName": "userId",
"dataType": "int",
The type you are using int and you are passing as varchar item and this will throw exception that string is not a number(NAN).
Either change the target type to string/varchar or change the source data type that you are using that matched with target.
Hope this will help you.

Insert does not work on model with composite id in loopback

I have a table named Xml_Mapping with composit ID on MYSQL.
When i try to insert into table; in runtime or from StrongLoop API Explorer, i could not insert.
When i debug, i see wrong insert sql :
INSERT INTO `Xml_Mapping`(`SiteId`,`SystemKeyId`,`TargetKey`) VALUES(1,1,'stockcode')
ON DUPLICATE KEY UPDATE
as you can see, "UPDATE" sql was not completed. So it could not be executed...
How can i solve this problem?
Xml_Mapping Table:
SiteId INT NOT NULL,
SystemKeyId INT NOT NULL,
TargetKey VARCHAR(100) NOT NULL,
PRIMARY KEY (SiteId, SystemKeyId, TargetKey),
CONSTRAINT XML_MAPPING_fk1 FOREIGN KEY (SiteId) REFERENCES site (Id),
INDEX XML_MAPPING_fk1 (SiteId)
Xml-mapping.json :
{
"name": "XmlMapping",
"base": "PersistedModel",
"idInjection": false,
"options": {
"validateUpsert": true
},
"mysql": {
"schema": "uygunca",
"table": "Xml_Mapping"
},
"properties": {
"SiteId": {
"type": "Number",
"id": 1,
"required": true,
"length": null,
"precision": 10,
"scale": 0,
"mysql": {
"columnName": "SiteId",
"dataType": "int",
"dataLength": null,
"dataPrecision": 10,
"dataScale": 0,
"nullable": "N"
},
"_selectable": false
},
"SystemKeyId": {
"type": "Number",
"id": 2,
"required": true,
"length": null,
"precision": 10,
"scale": 0,
"mysql": {
"columnName": "SystemKeyId",
"dataType": "int",
"dataLength": null,
"dataPrecision": 10,
"dataScale": 0,
"nullable": "N"
},
"_selectable": false
},
"TargetKey": {
"type": "String",
"id": 3,
"required": true,
"length": 100,
"precision": null,
"scale": null,
"mysql": {
"columnName": "TargetKey",
"dataType": "varchar",
"dataLength": 100,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
Alter your table Xml_Mapping and set autoincrement for field SiteId
and you don't need to provide SiteId in JSON
Run
ALTER TABLE `Xml_Mapping`
MODIFY `SiteId` int(10) NOT NULL AUTO_INCREMENT
Change your model Xml-mapping.json : and set properties for SiteId "required": false,
It should be like
{
"name": "XmlMapping",
"base": "PersistedModel",
"idInjection": false,
"options": {
"validateUpsert": true
},
"mysql": {
"schema": "uygunca",
"table": "Xml_Mapping"
},
"properties": {
"SiteId": {
"type": "Number",
"id": 1,
"required": false,
"length": null,
"precision": 10,
"scale": 0,
"mysql": {
"columnName": "SiteId",
"dataType": "int",
"dataLength": null,
"dataPrecision": 10,
"dataScale": 0,
"nullable": "N"
},
"_selectable": false
},
"SystemKeyId": {
"type": "Number",
"id": 2,
"required": true,
"length": null,
"precision": 10,
"scale": 0,
"mysql": {
"columnName": "SystemKeyId",
"dataType": "int",
"dataLength": null,
"dataPrecision": 10,
"dataScale": 0,
"nullable": "N"
},
"_selectable": false
},
"TargetKey": {
"type": "String",
"id": 3,
"required": true,
"length": 100,
"precision": null,
"scale": null,
"mysql": {
"columnName": "TargetKey",
"dataType": "varchar",
"dataLength": 100,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
and then use your JSON as
{
"SystemKeyId": 1,
"TargetKey": 'stockcode'
}

Strongloop PostgreSQL connector embedded model error

Got a simple Loopback API to retrieve tickets and responses using the postgreSQL connector. Tickets and responses come back fine individually but when I try to embed the responses into the ticket model I get the error below. I have tried following the documentation and I'm sure it's something simple in one of my relations that I'm missing but whatever I try, I cannot get it to work.
Any help would be appreciated.
https://docs.strongloop.com/display/public/LB/Embedded+models+and+relations#Embeddedmodelsandrelations-EmbedsMany
Ticket Model:
{
"name": "Ticket",
"base": "PersistedModel",
"idInjection": true,
"options": {
"postgresql": {
"schema": "customer_service",
"table": "tbl_ticket"
}
},
"properties": {
"description": {
"type": "String",
"required": true,
"length": null,
"precision": null,
"scale": null,
"postgresql": {
"columnName": "description",
"dataType": "text",
"dataLength": null,
"dataPrecision": null,
"dataScale": null,
"nullable": "NO"
}
},
"id": {
"type": "Number",
"id": 1,
"required": true,
"length": null,
"precision": 32,
"scale": 0,
"postgresql": {
"columnName": "id",
"dataType": "integer",
"dataLength": null,
"dataPrecision": 32,
"dataScale": 0,
"nullable": "NO"
}
}
},
"validations": [],
"relations": {
"responses": {
"type": "embedsMany",
"model": "Response",
"property": "embededResponses",
"options": {
"validate": true,
"forceId": false
}
}
},
"acls": [],
"methods": {}
}
Response Model:
{
"name": "Response",
"base": "PersistedModel",
"idInjection": true,
"options": {
"postgresql": {
"schema": "customer_service",
"table": "tbl_response"
}
},
"properties": {
"notes": {
"type": "String",
"required": false,
"length": null,
"precision": null,
"scale": null,
"postgresql": {
"columnName": "notes",
"dataType": "text",
"dataLength": null,
"dataPrecision": null,
"dataScale": null,
"nullable": "YES"
}
},
"ticketId": {
"type": "Number",
"required": true,
"length": null,
"precision": 32,
"scale": 0,
"postgresql": {
"columnName": "ticket_id",
"dataType": "integer",
"dataLength": null,
"dataPrecision": 32,
"dataScale": 0,
"nullable": "NO"
}
},
"id": {
"type": "Number",
"id": 1,
"required": true,
"length": null,
"precision": 32,
"scale": 0,
"postgresql": {
"columnName": "id",
"dataType": "integer",
"dataLength": null,
"dataPrecision": 32,
"dataScale": 0,
"nullable": "NO"
}
}
},
"validations": [],
"relations": {
"ticket": {
"type": "belongsTo",
"model": "Ticket",
"foreignKey": "ticketId"
}
},
"acls": [],
"methods": {}
}
Error:
{
"error": {
"name": "error",
"status": 500,
"message": "column \"embededresponses\" does not exist",
"length": 126,
"severity": "ERROR",
"code": "42703",
"position": "213",
"file": ".\\src\\backend\\parser\\parse_expr.c",
"line": "766",
"routine": "transformColumnRef",
"stack": "error: column \"embededresponses\" does not exist\n at Connection.parseE (C:\\WebApp\\node_modules\\loopback-connector-postgresql\\node_modules\\pg\\lib\\connection.js:539:11)\n at Connection.parseMessage (C:\\WebApp\\node_modules\\loopback-connector-postgresql\\node_modules\\pg\\lib\\connection.js:366:17)\n at Socket.<anonymous> (C:\\WebApp\\node_modules\\loopback-connector-postgresql\\node_modules\\pg\\lib\\connection.js:105:22)\n at Socket.emit (events.js:107:17)\n at readableAddChunk (_stream_readable.js:163:16)\n at Socket.Readable.push (_stream_readable.js:126:10)\n at TCP.onread (net.js:538:20)"
}
}
Your Ticket model should have the following relationship section:
"relations": {
"Responses": {
"type": "hasMany",
"model": "Response",
"foreignKey": "ticketId"
}
}
Your Response model relationship is correct.
It's not very clear from the docs that the embed relationships are for NoSQL databases. For traditional SQL databases, use the Has* relationship types.
To retrieve a Ticket with Responses from the REST API use the include filter: https://docs.strongloop.com/display/public/LB/Include+filter.
Example: localhost:3000/api/Tickets/{id}?filter[include]=responses
I am told that you can use embedded relations with SQL data sources, but the data is then stored in stringified-JSON format.
I've added a note to https://docs.strongloop.com/display/LB/Embedded+models+and+relations.
Rand