Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions funks.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,10 @@ module.exports.parseAssociations = function (dataModel) {
// set extra association fields
assoc["targetKey"] = association.targetKey;
assoc["targetKey_cp"] = capitalizeString(association.targetKey);
if (association.sourceKey) {
assoc["sourceKey"] = association.sourceKey;
assoc["sourceKey_cp"] = capitalizeString(association.sourceKey);
}
assoc["keysIn_lc"] = uncapitalizeString(association.keysIn);
assoc["holdsForeignKey"] = false;
assoc["assocThroughArray"] = false;
Expand Down Expand Up @@ -852,19 +856,22 @@ module.exports.parseAssociations = function (dataModel) {
// schema attrtibutes
associations_info.schema_attributes["one"][name] =
schema_attributes;
// holds foreignKey ?
if (association.keysIn === dataModel.model) {
if (association.sourceKey) {
assoc["assocThroughArray"] = true;
} else if (association.keysIn === dataModel.model) {
assoc["holdsForeignKey"] = true;
}
associations_info["to_one"].push(assoc);
break;
case "many_to_many":
assoc["assocThroughArray"] = true;
assoc["sourceKey"] = association.sourceKey;
case "one_to_many":
associations_info.schema_attributes["many"][name] =
schema_attributes;
associations_info["to_many"].push(assoc);
if (association.sourceKey) {
assoc["assocThroughArray"] = true;
}
break;
default:
break;
Expand Down
13 changes: 13 additions & 0 deletions test/integration_test_misc/integration_test_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,16 @@ module.exports.count_all_records = async function (count_func) {
let res = await module.exports.request_graph_ql_post(`{ ${count_func} }`);
return JSON.parse(res.body.toString("utf8")).data[count_func];
};

/**
* count_all_records - Count all records using given GraphQL query
*
* @param {count_func} {string} GraphQL count function name for the given table, e.g. 'countIndividuals'
* @return {integer} Number of the records in a given table
*/
module.exports.count_all_records_instance2 = async function (count_func) {
let res = await module.exports.request_graph_ql_post_instance2(
`{ ${count_func} }`
);
return JSON.parse(res.body.toString("utf8")).data[count_func];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"model": "bank",
"storageType": "cassandra",
"attributes": {
"bank_id": "String",
"foundation_year": "Int",
"district_id": "String",
"founder_id": "String"
},
"associations": {
"district": {
"type": "many_to_one",
"implementation": "foreignkeys",
"target": "district",
"targetKey": "bank_ids",
"sourceKey": "district_id",
"keysIn": "bank",
"targetStorageType": "cassandra",
"deletion":"update"
},
"unique_founder": {
"type": "one_to_one",
"implementation": "foreignkeys",
"target": "founder",
"targetKey": "bank_id",
"sourceKey": "founder_id",
"keysIn": "bank",
"targetStorageType": "cassandra",
"deletion":"update"
}
},
"internalId": "bank_id",
"id": {
"name": "bank_id",
"type": "String"
},
"useDataLoader": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"model": "dist_bank",
"storageType": "distributed-data-model",
"registry": ["dist_bank_instance1"],
"attributes": {
"bank_id": "String",
"foundation_year": "Int",
"district_id": "String",
"founder_id": "String"
},
"associations": {
"dist_district": {
"type": "many_to_one",
"implementation": "foreignkeys",
"target": "dist_district",
"targetKey": "bank_ids",
"sourceKey": "district_id",
"keysIn": "dist_bank",
"targetStorageType": "distributed-data-model",
"deletion":"update"
},
"dist_unique_founder": {
"type": "one_to_one",
"implementation": "foreignkeys",
"target": "dist_founder",
"targetKey": "bank_id",
"sourceKey": "founder_id",
"keysIn": "dist_bank",
"targetStorageType": "distributed-data-model",
"deletion":"update"
}
},
"internalId": "bank_id",
"id": {
"name": "bank_id",
"type": "String"
},
"useDataLoader": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"model": "dist_bank",
"storageType": "cassandra-adapter",
"adapterName": "dist_bank_instance1",
"regex": "instance1",
"attributes": {
"bank_id": "String",
"foundation_year": "Int",
"district_id": "String",
"founder_id": "String"
},
"associations": {
"dist_district": {
"type": "many_to_one",
"implementation": "foreignkeys",
"target": "dist_district",
"targetKey": "bank_ids",
"sourceKey": "district_id",
"keysIn": "dist_bank",
"targetStorageType": "distributed-data-model",
"deletion":"update"
},
"dist_unique_founder": {
"type": "one_to_one",
"implementation": "foreignkeys",
"target": "dist_founder",
"targetKey": "bank_id",
"sourceKey": "founder_id",
"keysIn": "dist_bank",
"targetStorageType": "distributed-data-model",
"deletion":"update"
}
},
"internalId": "bank_id",
"id": {
"name": "bank_id",
"type": "String"
},
"useDataLoader": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"model": "dist_district",
"storageType": "distributed-data-model",
"registry": ["dist_district_instance1"],
"attributes": {
"district_id": "String",
"district_name": "String",
"bank_ids": "[String]"
},
"associations": {
"dist_banks": {
"type": "one_to_many",
"implementation": "foreignkeys",
"target": "dist_bank",
"targetKey": "district_id",
"sourceKey": "bank_ids",
"keysIn": "dist_district",
"targetStorageType": "distributed-data-model",
"deletion":"update"
}
},
"internalId": "district_id",
"id": {
"name": "district_id",
"type": "String"
},
"useDataLoader": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"model": "dist_district",
"storageType": "cassandra-adapter",
"adapterName": "dist_district_instance1",
"regex": "instance1",
"attributes": {
"district_id": "String",
"district_name": "String",
"bank_ids": "[String]"
},
"associations": {
"dist_banks": {
"type": "one_to_many",
"implementation": "foreignkeys",
"target": "dist_bank",
"targetKey": "district_id",
"sourceKey": "bank_ids",
"keysIn": "dist_district",
"targetStorageType": "distributed-data-model",
"deletion":"update"
}
},
"internalId": "district_id",
"id": {
"name": "district_id",
"type": "String"
},
"useDataLoader": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"model": "dist_field",
"storageType": "distributed-data-model",
"registry": ["dist_field_instance1"],
"attributes": {
"field_id": "String",
"field_name": "String",
"owner": "String",
"plant_ids": "[String]"
},
"associations": {
"dist_plants": {
"type": "one_to_many",
"implementation": "foreignkeys",
"target": "dist_plant",
"targetKey": "field_id",
"sourceKey": "plant_ids",
"keysIn": "dist_field",
"targetStorageType": "distributed-data-model",
"deletion":"update"
}
},
"internalId": "field_id",
"id": {
"name": "field_id",
"type": "String"
},
"useDataLoader": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"model": "dist_field",
"storageType": "mongodb-adapter",
"adapterName": "dist_field_instance1",
"regex": "instance1",
"attributes": {
"field_id": "String",
"field_name": "String",
"owner": "String",
"plant_ids": "[String]"
},
"associations": {
"dist_plants": {
"type": "one_to_many",
"implementation": "foreignkeys",
"target": "dist_plant",
"targetKey": "field_id",
"sourceKey": "plant_ids",
"keysIn": "dist_field",
"targetStorageType": "distributed-data-model",
"deletion":"update"
}
},
"internalId": "field_id",
"id": {
"name": "field_id",
"type": "String"
},
"useDataLoader": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"model": "dist_founder",
"storageType": "distributed-data-model",
"registry": ["dist_founder_instance1"],
"attributes": {
"founder_id": "String",
"bank_id": "String",
"name": "String"
},
"associations": {
"dist_unique_bank": {
"type": "one_to_one",
"implementation": "foreignkeys",
"target": "dist_bank",
"targetKey": "founder_id",
"sourceKey": "bank_id",
"keysIn": "dist_founder",
"targetStorageType": "distributed-data-model",
"deletion":"update"
}
},
"internalId": "founder_id",
"id": {
"name": "founder_id",
"type": "String"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"model": "dist_founder",
"storageType": "cassandra-adapter",
"adapterName": "dist_founder_instance1",
"regex": "instance1",
"attributes": {
"founder_id": "String",
"bank_id": "String",
"name": "String"
},
"associations": {
"dist_unique_bank": {
"type": "one_to_one",
"implementation": "foreignkeys",
"target": "dist_bank",
"targetKey": "founder_id",
"sourceKey": "bank_id",
"keysIn": "dist_founder",
"targetStorageType": "distributed-data-model",
"deletion":"update"
}
},
"internalId": "founder_id",
"id": {
"name": "founder_id",
"type": "String"
}
}
Loading