Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Self-reference #59

Closed
frnco opened this issue Jun 30, 2014 · 5 comments
Closed

Self-reference #59

frnco opened this issue Jun 30, 2014 · 5 comments

Comments

@frnco
Copy link

frnco commented Jun 30, 2014

Trying to self-reference on a oneToMany relationship ("Parent" column) breaks the area with ER_NONUNIQ_TABLE.

@simov
Copy link
Owner

simov commented Jun 30, 2014

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?

@frnco
Copy link
Author

frnco commented Jun 30, 2014

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
    }
}

@theRichu
Copy link
Contributor

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

@simov
Copy link
Owner

simov commented Jul 21, 2014

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

@simov
Copy link
Owner

simov commented Jul 22, 2014

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

@simov simov closed this as completed Jul 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants