Comments (8)
Yes I know that this is possible in MySql, but currently it's not supported in Express Admin. Probably it will be implemented in the future but I can't promise you anything at the moment. I'll think about how it should be implemented.
from express-admin.
@simov Thanks for the response! I'll look for another solution for the time being.
from express-admin.
Hi, I just incurred in the same issue and I thought about a possible patch. It's not complete yet could be a starting point for a full fix.
--- express-admin/lib/core/editview.js
+++ express-admin/lib/core/editview.js
@@ -80,9 +80,20 @@
names = sql.fullNames(table.name, names);
names.unshift(sql.pk(table.name, table.pk));
-
+ var key = (args.fk? args.fk:table.pk);
+ var val = args.id;
+ if (Array.isArray(table.pk)) {
+ key = table.pk[0];
+ var ids = args.id.split('-=-');
+ val = '"' + ids[0] + '"' ;
+ for (var i=1; i < table.pk.length; i++) {
+ val += ' AND `' +
+ table.name + '`.`' + table.pk[i] + '` = "' +
+ ids[i] + '"';
+ }
+ }
return query.replace('get-record',
- names.join(), table.name, (args.fk? args.fk:table.pk), args.id);
+ names.join(), table.name, key, val);
},
getRecords: function (args, cb) {
if (args.post) {
--- express-admin/lib/utils/routes.js
+++ express-admin/lib/utils/routes.js
@@ -17,7 +17,7 @@
custom: null,
anything: /(?:\/.*)?/,
list: /(?:\/\?p=\d+)?/i,
- edit: /\/(\d+|add)/i,
+ edit: /\/(.+|add)/i,
home: /^\/$/,
$: /\/?$/i
};
--- express-admin/lib/utils/sql.js
+++ express-admin/lib/utils/sql.js
@@ -33,7 +33,9 @@
*/
exports.fullName = function (table, column) {
- var result = ['`',table,'`.`',column,'`'].join('');
+ var result = Array.isArray(column)
+ ? 'CONCAT(`'+table+'`.`'+column.join('`,"_",`'+table+'`.`')+'`)'
+ : ['`',table,'`.`',column,'`'].join('');
return quotes(result);
}
--- express-admin/lib/utils/settings.js
+++ express-admin/lib/utils/settings.js
@@ -106,15 +106,21 @@
*/
function primaryKey (columns) {
+ var pk = [];
for (var name in columns) {
for (var property in columns[name]) {
if (columns[name][property] === 'pri') {
- return name;
+ pk.push(name);
}
}
}
- return '';
+ switch (pk.length) {
+ case 0 : return ""; break;
+ case 1 : return pk[0]; break;
+ default: return pk;
+ }
}
/**
* This is not used at all, it stays here only for explanation.
from express-admin.
Yes, I'm starting to think about this. @t-i-e just don't waste time to create a pull request, because I'm doing a major refactoring on the code base.
from express-admin.
Hi, @sankethkatta @t-i-e
This was implemented in version 1.2.2
Make sure you check out the docs, basically all settings constructions are the same but you can have arrays for primary keys in each place specifying a relationship, and for table's primary key as well.
Another place to look at is the system tests repository for Express Admin, to see how I tested this functionality. There are model files in fixtures, as well as all configuration files.
🍻
from express-admin.
Install version >=1.2.3 !
from express-admin.
excuse me, I'm not good at English...The primary key only allows for int type? My data's pk is date...
from express-admin.
I don't have tests with date pk exactly, but from version 1.2.3 you can use anything as pk.
from express-admin.
Related Issues (20)
- nsp security issues HOT 1
- Store comma seperated values for a single column.
- Passing parameters to /add in order to prevalue fields
- mysql insert operation not working in -v (development, no login) mode HOT 1
- Time is not shown correctlly for mysql db HOT 1
- Unhandled exception when paginating empty resultsets
- Ajax call not working
- Error creating entry with many to many relationship
- crashes under Firefox Quantum 62.0 (64-bit) under OSX
- Support for postgres data type json? HOT 4
- ERROR! Could not find `pg` or `pg.js` module HOT 1
- Can this be used with hapijs? HOT 1
- PG setup via connection string
- Datepicker saving timezone with timestamp HOT 1
- Empty one to Many HOT 4
- Filter in tables throw internal server error HOT 1
- Password authentication fails for Postgres (11) connections HOT 4
- Flash of unstyled content HOT 3
- how to configure server using nodemon HOT 1
- what is mean for this error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express-admin.