Customfields attached to addresses break the profile page
General
When we set an address customfield on an address and then we add that field into a profile, the profile page breaks on edit mode.
Returning error: DB Error: no such field
How to reproduce
On https://dmaster.demo.civicrm.org (CiviCRM 5.20.alpha1) :
- Create a new CustomGroup and assign it to the entity 'Address'
- Create a new customfield (for example of type textfield)
- Populate the field with some dummy information
- Create a new profile and add 2 fields:
- Street Address
- Your newly created customfield
- Click on 'More -> Use edit mode'
- The page should break with error
DB Error: no such field
Background
It seems that the issue starts here: https://lab.civicrm.org/dev/core/blob/master/CRM/Contact/BAO/Contact.php#L1784 and then goes here: https://lab.civicrm.org/dev/core/blob/master/CRM/Contact/BAO/Query.php#L1036
and the actual join should take place somewhere here: https://lab.civicrm.org/dev/core/blob/master/CRM/Contact/BAO/Query.php#L1307
In short: There is an additional field, the id of the customtable that is holding the customfield in the select query that is not being joined properly (join is actually missing) from the constructed query.