Skip to content

Duplicate column names conflicting even when using table aliases #21

@gastongr

Description

@gastongr

Hello @zepernick , just wanted to report the following problem:

I have two tables, 'products' and 'product_types', both having a 'name' column. I want to display the products table with the product type, so i joined both tables in products.product_type_id=product_types.id

In my Model:

    public function joinArray(){
        return array(
                'product_types pt|left outer' => 'pt.id = p.product_type_id',
        );
    }

    public function fromTableStr() {
        return 'products p';
    }

The javascript with column names:

        $('#recordsTable').dataTable( {
        processing: true,
        serverSide: true,
        ajax: {
            'url': BASE_URL + '/products/dataTable',
            'type': 'POST'
        },
        columns: [
            {data: 'p.name'},
            {data: 'pt.name'},
            {data: 'p.sale_price'},
            {data: 'p.barcode'}
        ],
    });

The problem is that the name fields are blank and in some cases both are filled with the same data.

In the json response values are wrong, but the db query is right.
So i guess the problem is when building the response and i couldn't find how to fix it.

Alternatively i'm adding duplicate field names using appendToSelectStr() since it allows aliases, however it would be nice to get it right.

Please if you can help it will be greatly appreciated :)

Thanks for the great library!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions