I have a models for a user built form as follows:
Form
id
title
FormField
id
type
name
label
FormEntry
id
form_id
date
FormFieldEntry
id
form_entry_id
form_field_id
value
I am trying to formulate a sql query on Form that will have the FormField labels as column names and the FormFieldEntry’s as the values.
The only way to accomplish what you seek is to use dynamic SQL. You must assemble the SQL statement string in code by querying for the column names and send it to the database. The resulting SQL statement you build might look something like: