Skip to content

Commit 73efa47

Browse files
authored
force set refersTo property (#254)
* force set refersTo property * set refersTp only for association of type junction * 2.6.105
1 parent 9861e9d commit 73efa47

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

data-model.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,6 +2621,10 @@ DataModel.prototype.inferMapping = function(name) {
26212621
}
26222622
//extend default mapping attributes
26232623
var mapping = _.assign(defaultMapping, field.mapping);
2624+
// set refersTo property if it's not defined in mapping
2625+
if (mapping.refersTo == null && mapping.associationType === 'junction') {
2626+
mapping.refersTo = field.name;
2627+
}
26242628

26252629
var associationAdapter;
26262630
if (mapping.associationType === 'junction' && mapping.associationAdapter && typeof mapping.associationObjectField === 'undefined') {
@@ -2629,7 +2633,7 @@ DataModel.prototype.inferMapping = function(name) {
26292633
if (associationAdapter) {
26302634
// try to find association adapter parent field
26312635
var associationParentAttr = _.find(associationAdapter.attributes, function (x) {
2632-
return (x.primary === 'undefined' || x.primary === false) && x.type === mapping.parentModel;
2636+
return (typeof x.primary === 'undefined' || x.primary === false) && x.type === mapping.parentModel;
26332637
});
26342638
if (associationParentAttr) {
26352639
mapping.associationObjectField = associationParentAttr.name;
@@ -2655,7 +2659,7 @@ DataModel.prototype.inferMapping = function(name) {
26552659
if (associationAdapter) {
26562660
// try to find association adapter parent field
26572661
var associationChildAttr = _.find(associationAdapter.attributes, function (x) {
2658-
return typeof (x.primary === 'undefined' || x.primary === false) && x.type === mapping.childModel;
2662+
return typeof (typeof x.primary === 'undefined' || x.primary === false) && x.type === mapping.childModel;
26592663
});
26602664
if (associationChildAttr) {
26612665
mapping.associationValueField = associationChildAttr.name;

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@themost/data",
3-
"version": "2.6.104",
3+
"version": "2.6.105",
44
"description": "MOST Web Framework Codename Blueshift - Data module",
55
"main": "index.js",
66
"types": "index.d.ts",

0 commit comments

Comments
 (0)