django-rest-framework-datatables icon indicating copy to clipboard operation
django-rest-framework-datatables copied to clipboard

'AND' queries between multiple columns is not working

Open matthewhegarty opened this issue 4 years ago • 3 comments

Whilst submitting the answer to #97 I noticed that the AND behaviour is not supported.

The docs say:

The values within a single name field are tied together using a logical OR operator for filtering, while those between name fields are strung together with an AND operator. This means that Datatables’ multicolumn search functionality is preserved.

(e.g. for albums_by_decade)

        "columns": [
            {"data": "rank", "searchable": false},
            {"data": "artist.name", "name": "artist.name, year"},
            {"data": "name"},
            {"data": "year"},
            {"data": "genres", "name": "genres.name", "sortable": false},
        ]

However, if you examine the SQL produced by the example app there is no AND query produced:

SELECT DISTINCT "albums_album"."id",
                "albums_album"."name",
                "albums_album"."rank",
                "albums_album"."year",
                "albums_album"."artist_id"
FROM "albums_album"
         INNER JOIN "albums_artist" ON ("albums_album"."artist_id" = "albums_artist"."id")
         LEFT OUTER JOIN "albums_album_genres" ON ("albums_album"."id" = "albums_album_genres"."album_id")
         LEFT OUTER JOIN "albums_genre" ON ("albums_album_genres"."genre_id" = "albums_genre"."id")
WHERE ("albums_artist"."name" LIKE '%19%' ESCAPE '\' OR "albums_album"."year" LIKE '%19%' ESCAPE '\' OR
 "albums_album"."name" LIKE
 '%19%' ESCAPE '\' OR
   "albums_album"."year" LIKE
   '%19%' ESCAPE
   '\' OR "albums_genre"."name" LIKE '%19%' ESCAPE '\')
ORDER BY "albums_album"."rank" ASC
LIMIT 10;

Is this a bug or have I misunderstood how this works?

matthewhegarty avatar Feb 12 '21 15:02 matthewhegarty

I have to check that, I can't remember the expected behavior.

izimobil avatar Apr 21 '21 17:04 izimobil

Also having issues with AND query functionality.

AustinGilkison avatar Jan 17 '22 18:01 AustinGilkison

OK. Care to elaborate ?

izimobil avatar Jan 17 '22 21:01 izimobil