Giter VIP home page Giter VIP logo

Comments (8)

simov avatar simov commented on May 21, 2024

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.

sankethkatta avatar sankethkatta commented on May 21, 2024

@simov Thanks for the response! I'll look for another solution for the time being.

from express-admin.

t-i-e avatar t-i-e commented on May 21, 2024

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.

simov avatar simov commented on May 21, 2024

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.

simov avatar simov commented on May 21, 2024

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.

simov avatar simov commented on May 21, 2024

Install version >=1.2.3 !

from express-admin.

shhider avatar shhider commented on May 21, 2024

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.

simov avatar simov commented on May 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.