I'd like to use db_select() to extract values from a field collection attached to the user profile, to help speed up some complex Ajax forms (rather than loading the entire field collection, using standard entity queries, etc, etc).
Assuming I have the following:
Field Collection: field_my_address
Field 1: field_street_number
(integer field)
Field 2: field_street_name
(text field)
Field 3: field_city
(taxonomy term reference field)
How would I go about doing this?
field_data_[FIELD_NAME]
e.g.field_data_field_street_name
and make sure that entity_id and entity_type are set. My one gotcha there is that if you use a placeholder for entity_type, there's a bug (or hidden feature?) where you can only set the same placeholder name once. (Edit) You'll also need to look up the field storage schema (hook_field_schema) for those fields, but I think the columns would beFIELD_NAME_value
andFIELD_NAME_tid
respectively. – mradcliffe Jul 10 '18 at 18:19