Coder Social home page Coder Social logo

Self-reference about express-admin HOT 5 CLOSED

simov avatar simov commented on May 22, 2024
Self-reference

from express-admin.

Comments (5)

simov avatar simov commented on May 22, 2024

Can you paste the part of your config you are working on, also what your tables configuration is, and what you are trying to achieve?

from express-admin.

frnco avatar frnco commented on May 22, 2024

Of course. I need to have categories, many of them with sub-categories. I'm doing this through a column called "parent" which basically has the ID of another category. If this column's value is 0 this category has no Parent.

For the settings of this table as it is today, here goes:

"categories": {
    "slug": "categories",
    "table": {
        "name": "categories",
        "pk": "id",
        "verbose": "Categories"
    },
    "columns": [
        {
            "name": "id",
            "verbose": "id",
            "control": {
                "text": true
            },
            "type": "int(11)",
            "allowNull": true,
            "defaultValue": null,
            "listview": {
                "show": false
            },
            "editview": {
                "show": true
            }
        },
        {
            "name": "name",
            "verbose": "Name",
            "control": {
                "text": true
            },
            "type": "varchar(255)",
            "allowNull": false,
            "defaultValue": null,
            "listview": {
                "show": true
            },
            "editview": {
                "show": true
            }
        },
        {
            "name": "parent",
            "verbose": "parent",
            "control": {
                "select": true
            },
            "oneToMany": {
                "table": "categories",
                "pk": "id",
                "columns": [
                    "nome"
                ]
            },
            "type": "int(11)",
            "allowNull": true,
            "defaultValue": 0,
            "listview": {
                "show": true
            },
            "editview": {
                "show": true
            }
        },
    ],
    "mainview": {
        "show": true
    },
    "listview": {
        "order": {},
        "page": 25
    },
    "editview": {
        "readonly": false
    }
}

from express-admin.

theRichu avatar theRichu commented on May 22, 2024

I just came across this problem :(
How can it solve?

from express-admin.

simov avatar simov commented on May 22, 2024

The query generated for the listview looks like this

SELECT `tbl`.`id` AS __pk,`tbl`.`name`,
GROUP_CONCAT(DISTINCT CONCAT_WS(' ',CAST(`tbl`.`name` AS CHAR))) AS `parent` 
FROM `tbl`  
LEFT JOIN `tbl` ON `tbl`.`parent` = `tbl`.`id`   
GROUP BY `tbl`.`id`  ORDER BY `tbl`.`id` ASC LIMIT 0,25 ;

but in case of a self reference, it should be transformed to this

SELECT `tbl`.`id` AS __pk,`tbl`.`name`,
GROUP_CONCAT(DISTINCT CONCAT_WS(' ',CAST(`tbl2`.`name` AS CHAR))) AS `parent` 
FROM `tbl`  
LEFT JOIN `tbl` `tbl2` ON `tbl2`.`parent` = `tbl`.`id`   
GROUP BY `tbl`.`id`  ORDER BY `tbl`.`id` ASC LIMIT 0,25 ;

the only difference is the alias

I'll definitely think about it

from express-admin.

simov avatar simov commented on May 22, 2024

@ellahn @theRichu just pushed to master, if you are anxious to try it out just pull (it's not published to npm yet)

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.