izimobil / django-rest-framework-datatables

Seamless integration between Django REST framework and Datatables.
http://django-rest-framework-datatables.readthedocs.io/en/latest/
MIT License
395 stars 89 forks source link

'AND' queries between multiple columns is not working #100

Open matthewhegarty opened 3 years ago

matthewhegarty commented 3 years ago

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?

izimobil commented 3 years ago

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

AustinGilkison commented 2 years ago

Also having issues with AND query functionality.

izimobil commented 2 years ago

OK. Care to elaborate ?