Pegase745 / sqlalchemy-datatables

SQLAlchemy integration of jQuery DataTables >= 1.10.x (Pyramid and Flask examples)
MIT License
159 stars 67 forks source link

How to search column with func.group_concat? #118

Open gotounix opened 5 years ago

gotounix commented 5 years ago

I have a cloumn such as:

ColumnDT(func.group_concat(distinct(Role.name)), global_search=False, mData='roles'),

And search in DataTables not working for this column. I found while I using having everything is okey.

SELECT * FROM users 
LEFT OUTER JOIN users_roles ON users.id = users_roles.user_id 
LEFT OUTER JOIN roles ON roles.id = users_roles.role_id 
having group_concat(DISTINCT roles.name) LIKE lower('%admin%')

But the real sql is using where.

Is there a way to solve it?

tdamsma commented 5 years ago

No, that is not supported directly, search input is translated to a where clause. Probably you can work around this by doing a subquery first and then filtering (using where) in the outer query