Skip to content

getRulesFromSQL() : Auto detect field IDs by field names using the already defined config. #461

@gordon-matt

Description

@gordon-matt

As 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions