I use the SOAP API (WSC, partner wsdl) to describe objects and use the field meta information to dynamically build SOQL queries. Today i observed that DescribeSObjectResult can contain fields of type reference but with an unknown (empty) relationship name.
These reference fields are not usable to build SOQL queries because of the missing relationship name that must be used in a field path.
For Example the description of the User object contains a reference field 'AccountId' that contains the correct referenceTo property ('Account') but an empty relationshipName.
Why this can happen?
I can imaging that these fields are only used/enabled in some specific cases? The User.AccountId field seems to be only used for Customer Portal users (when communities are enabled in an organization).
A complete list of fields (describeGlobal, developer org) that are of type reference but with an empty relationship name:
User -> DelegatedApproverId
User -> AccountId
User -> CallCenterId
ContentDocument -> ArchivedById
ContentDocument -> ParentId
FiscalYearSettings -> PeriodId
LoginHistory -> UserId
Group -> RelatedId
CaseShare -> UserOrGroupId
RecordType -> BusinessProcessId
Campaign -> CampaignMemberRecordTypeId
WebLink -> ScontrolId
DocumentAttachmentMap -> ParentId
DocumentAttachmentMap -> DocumentId
Task -> RecurrenceActivityId
ContentVersion -> ContentModifiedById
CategoryNode -> ParentId
ContentWorkspace -> DefaultRecordTypeId
LeadShare -> UserOrGroupId
AccountPartner -> ReversePartnerId
CronTrigger -> OwnerId
OpportunityShare -> UserOrGroupId
CampaignMemberStatus -> CampaignId
ApexTestQueueItem -> ParentJobId
ForecastShare -> UserRoleId
ForecastShare -> UserOrGroupId
UserRecordAccess -> UserId
AsyncApexJob -> ParentJobId
SetupEntityAccess -> SetupEntityId
IdeaComment -> CommunityId
UserRole -> ParentRoleId
UserRole -> ForecastUserId
UserRole -> PortalAccountId
UserRole -> PortalAccountOwnerId
CaseTeamTemplateMember -> TeamTemplateId
CaseTeamTemplateMember -> MemberId
CaseTeamTemplateMember -> TeamRoleId
AuthProvider -> RegistrationHandlerId
AuthProvider -> ExecutionUserId
AdditionalNumber -> CallCenterId
Event -> RecurrenceActivityId
OpportunityPartner -> ReversePartnerId
CampaignShare -> UserOrGroupId
ContactShare -> UserOrGroupId
EmailTemplate -> BrandTemplateId
EmailServicesAddress -> RunAsUserId
Report -> OwnerId
CategoryData -> CategoryNodeId
CategoryData -> RelatedSobjectId
Partner -> ReversePartnerId
AccountShare -> UserOrGroupId
UserPreference -> UserId
GroupMember -> UserOrGroupId
SelfServiceUser -> ContactId
EmailServicesFunction -> ApexClassId