Note: speaking from a pure SQL point of perspective, since I haven't worked with gorm yet:
In my comment above I asked:
How would you know if the ID in CustomerOrCompanyID is a customer ID or a company ID? Do you have some boolean field saying this is a customer or not? Or does the ID itself contain that information? Like cust-1234 and comp-1234?
Since you need a way to distinguish what kind of ID is in CustomerOrCompanyID anyway, I'd suggest to have two fields: CustomerID and CompanyID. One of them is always 0 (or NULL).
That way you know which table to join in and can also join in both at the same time depending on what data type each row has, the columns for the customer or the company will be filled.
I think gorm should not have a problem anymore if there are 2 fields as it would handle each of them as a normal relation that is not set for all columns.
Some example SQL statements (MySQL Dialekt):
All customers:
SELECT
Relation.ID as RelID, Relation.OtherColumn,
Customer.ID, Customer.Name
/* etc. */
FROM
Relation INNER JOIN Customer ON (Relation.CustomerID=Customer.ID);
All companies:
SELECT
Relation.ID as RelID, Relation.OtherColumn,
Company.ID, Company.Name
/* etc. */
FROM
Relation INNER JOIN Company ON (Relation.CompanyID=Company.ID);
You might also want all data in Relation with the columns of Company and Customer and decide in the frontend which ones to use:
SELECT
Relation.ID as RelID,
Relation.OtherColumn,
Customer.ID as CustID,
Customer.Name as CustName,
Company.ID as CompID,
Company.Name as CompName,
/* etc. */
FROM
Relation
LEFT JOIN Company ON (Relation.CompanyID=Company.ID)
LEFT JOIN Customer ON (Relation.CustomerID=Customer.ID);