harrygulliford / laravel-firebird

Firebird database driver for the Laravel Framework
65 stars 30 forks source link

Json response in Laravel with fields adding underscores #17

Closed selectmatica closed 3 years ago

selectmatica commented 3 years ago

In a laravel query where there is a relationship between belongsTo articles and their section, family and subfamily, I get this result: "code": 200,

  "data": {
        "CODIGO": "501",
        "NOMBRE": "CAJA 30",
        "SECCION": "PTC",
        "FAMILIA": "00-13",
        "SUBFAMILIA": "67",
        "MARCA": "1",
        "TIPO_IVA": 2,
        "BAJA": "N   ",
        "ACTUALIZA_PVP": "S   ",
        "PUBLICAR_WEB": "S   ",
        "s_e_c_c_i_o_n": {
            "CODIGO": "PTC",
            "DESCRIPCION": "CAJAS COMPUESTAS"
        },
        "f_a_m_i_l_i_a": {
            "CODIGO": "00-13",
            "DESCRIPCION": "STATICE"
        },
        "s_u_b_f_a_m_i_l_i_a": {
            "CODIGO": "67",
            "DESCRIPCION": "STATICE EXTRA"
        }
    }

As you can see, I get the results I need, but in addition to duplicating the section, family and subfamily fields, I also change their name by adding underscores between the letters.

Can this be solved? Thank you.

harrygulliford commented 3 years ago

This is due to Firebird returning uppercase keys for the column names. I may look at converting keys to lowercase in a future release to keep in-line with the Laravel style/conventions, but this would be a breaking change.