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