getRulesFromSQL() : Auto detect field IDs by field names using the already defined config.
See original GitHub issueAs per the last comment on issue #452 , I would like to ask for getRulesFromSQL()
to be modified to determine the correct IDs based on the Field Names. At first, this was only going to be a request for convenience sake, but I have just discovered an issue where this is actually very important (at least to me anyway) and will probably need to involve the SQL parser being updated as well:
I have successfully been able to do a joined query by basically setting the field names in my config with a prefix… Example:
filters: [
{ id: 'booking-id', field: '"B"."Id"', label: 'Booking: ID' },
{ id: 'booking-code', field: '"B"."Code"', label: 'Booking: Code' },
{ id: 'booking-date', field: '"B"."BookingDate"', label: 'Booking: Date' },
{ id: 'booking-destination', field: '"B"."Destination"', label: 'Booking: Destination' },
//etc
{ id: 'customer-id', field: '"C"."Id"', label: 'Customer: ID' },
{ id: 'customer-email', field: '"C"."Email"', label: 'Customer: Email' },
//etc
]
Then, in the backend, I simply create my SQL query as follows:
SELECT *
FROM "Bookings" AS "B"
INNER JOIN "Customers" "C" ON "C"."Id" = "B"."CustomerId"
WHERE <Query From QueryBuilder Goes Here>
It works beautifully. But then when I want to load a saved query, it doesn’t work because this is obviously not supported in the SQL parser. I would like to suggest that QueryBuilder already has the field definitions, so in theory it shouldn’t be too hard to simply match each field name with an ID automatically. For example, “C”.“Id” would be matched to the ID “customer-id”.
What’s the possibility of having this done?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
There are two commits linked to this issue, one being https://github.com/mistic100/jQuery-QueryBuilder/commit/c1c451e2777d63a53615caba0f00991d75da3a59
Hi there. It’s been 2 years since I opened this request. I am working on a new project that will be using this Query Builder… and I was just looking at this issue again and noticed that the last thing that happened here was you made a fix, but only for Mongo. Is this fix now applied to SQL as well?