mirror of
https://github.com/strapi/strapi.git
synced 2025-08-11 10:18:28 +00:00
Merge pull request #426 from strapi/enhancement/one-way
Fix #379 - Support one-way relationship
This commit is contained in:
commit
cffbc61dba
@ -46,4 +46,4 @@
|
||||
"npm": ">= 3.0.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
|
@ -55,4 +55,4 @@
|
||||
"npm": ">= 5.3.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
|
@ -46,4 +46,4 @@
|
||||
"npm": ">= 5.0.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
|
@ -251,7 +251,7 @@ module.exports = function (strapi) {
|
||||
const FK = _.find(definition.associations, {alias: name});
|
||||
const ref = details.plugin ? strapi.plugins[details.plugin].models[details.model].globalId : strapi.models[details.model].globalId;
|
||||
|
||||
if (FK && FK.nature !== 'oneToOne' && FK.nature !== 'manyToOne') {
|
||||
if (FK && FK.nature !== 'oneToOne' && FK.nature !== 'manyToOne' && FK.nature !== 'oneWay') {
|
||||
definition.loadedModel[name] = {
|
||||
type: 'virtual',
|
||||
ref,
|
||||
|
@ -35,6 +35,7 @@ class EditFormRelations extends React.Component { // eslint-disable-line react/p
|
||||
const relations = map(currentSchema.relations, (relation, i) => {
|
||||
|
||||
switch (relation.nature) {
|
||||
case 'oneWay':
|
||||
case 'oneToOne':
|
||||
case 'manyToOne':
|
||||
if (relation.dominant) {
|
||||
|
@ -77,6 +77,10 @@ module.exports = {
|
||||
acc[current] = params.values[current];
|
||||
} else {
|
||||
switch (association.nature) {
|
||||
case 'oneWay':
|
||||
acc[current] = _.get(params.values[current], this.primaryKey, params.values[current]) || null;
|
||||
|
||||
break;
|
||||
case 'oneToOne':
|
||||
if (response[current] !== params.values[current]) {
|
||||
const value = _.isNull(params.values[current]) ? response[current] : params.values;
|
||||
|
@ -58,6 +58,10 @@ module.exports = {
|
||||
acc[current] = params.values[current];
|
||||
} else {
|
||||
switch (association.nature) {
|
||||
case 'oneWay':
|
||||
acc[current] = _.get(params.values[current], this.primaryKey, params.values[current]) || null;
|
||||
|
||||
break;
|
||||
case 'oneToOne':
|
||||
if (response[current] !== params.values[current]) {
|
||||
const value = _.isNull(params.values[current]) ? response[current] : params.values;
|
||||
|
@ -70,7 +70,6 @@ module.exports = {
|
||||
// Create an entry using `queries` system
|
||||
ctx.body = await strapi.plugins['content-manager'].services['contentmanager'].add(ctx.params, ctx.request.body, source);
|
||||
} catch(error) {
|
||||
console.log(error);
|
||||
ctx.badRequest(null, ctx.request.admin ? [{ messages: [{ id: error.message, field: error.field }] }] : error.message);
|
||||
}
|
||||
},
|
||||
|
@ -48,4 +48,4 @@
|
||||
"react-select": "^1.0.0-rc.5",
|
||||
"strapi-helper-plugin": "3.0.0-alpha.7.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,4 +48,4 @@
|
||||
"npm": ">= 3.0.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
|
@ -46,4 +46,4 @@
|
||||
"npm": ">= 3.0.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
|
@ -45,4 +45,4 @@
|
||||
"npm": ">= 3.0.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
|
@ -48,4 +48,4 @@
|
||||
"npm": ">= 3.0.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user