express-admin
express-admin copied to clipboard
OneToMany mapping with two tables
Hello team,
I've a Category masters table with column (name, parent) Topic table with columns (name, category_id) SubTopic table with columns (name, topic_id)
The way I want to show topic_id in Listing UI is name-category(Actual category name) Below is my code
"name": "topic_id",
"verbose": "Topic",
"control": {
"select": true
},
"oneToMany": {
"table": "topic",
"pk": "id",
"columns": [
"name",
"category_id"
]
},
"type": "int(100)",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
The above code produces output as
(name)cartoon 1(category_id)
where cartoon is name 1 is the category_id Here instead of 1 I want the actual category name.
Please help.
Currently it's not possible to configure such relationship through the configuration.
ok Thank You
Hello,
I'm trying a work around
I've created a field helpertext in topic table that is hidden. So when I save the topic table I have written a preSave event to save the helpertext as (name)cartoon 1(category_id)
exports.preSave = function (req, res, args, next) {
if (args.debug) console.log('preSave');
debugger;
if (args.name == 'topic') {
record = args.data.view.topic.records[0].columns;
record.helpertext = record.name + "-" + record.category_id;
console.log(JSON.stringify(record));
}
next();
}
but instead of this I want category name. So I did this
exports.preSave = function (req, res, args, next) {
if (args.debug) console.log('preSave');
debugger;
if (args.name == 'topic') {
record = args.data.view.topic.records[0].columns;
var inline = args.data.manyToOne.topic;
console.log(JSON.stringify(args.data));
record.helpertext = record.category_id + "-" + record.name;
console.log(JSON.stringify(record));
}
next();
}
I am getting error at var inline = args.data.manyToOne.topic;
Please help
+1. Would love to see this feature