Merge pull request #426 from strapi/enhancement/one-way

Fix #379 - Support one-way relationship
This commit is contained in:
Jim LAURIE 2018-01-09 11:15:10 +01:00 committed by GitHub
commit cffbc61dba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 18 additions and 10 deletions

View File

@ -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,

View File

@ -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) {

View File

@ -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;

View File

@ -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;

View File

@ -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);
}
},