Skip to content

Conversation

@jeffdgr8
Copy link

@jeffdgr8 jeffdgr8 commented May 24, 2018

When NSDictionaryResultType is used on a fetch request and a selected column is present on a joined table, an "ambiguous column name: columnName" error results. The columns should be prefixed with tableName.columnName to avoid this ambiguity.

I experienced this error EncryptedStoreErrorMessage = "ambiguous column name: serverId" with a fetch request on User with the predicate unit.domainLeft >= 11 AND unit.domainRight <= 16, where User.unit -> OrgUnit and both User and OrgUnit have serverId columns.

The SQL query generated by ECD:

SELECT DISTINCT serverId, localId FROM ecdUser
LEFT OUTER JOIN ecdOrgUnit AS [unit] ON ecdUser.unit__objectid = [unit].__objectID 
WHERE ([unit].domainLeft >= ? AND [unit].domainRight <= ?);

And the SQL query generated by the default NSSQLiteStoreType:

SELECT t0.ZSERVERID, t0.ZLOCALID FROM ZUSER t0
JOIN ZORGUNIT t1 ON t0.ZUNIT = t1.Z_PK
WHERE ( t1.ZDOMAINLEFT >= ? AND  t1.ZDOMAINRIGHT <= ?) 

With these changes, the ECD query is now:

SELECT DISTINCT ecdUser.serverId, ecdUser.localId FROM ecdUser 
LEFT OUTER JOIN ecdOrgUnit AS [unit] ON ecdUser.unit__objectid = [unit].__objectID  
WHERE ([unit].domainLeft >= ? AND [unit].domainRight <= ?);

When NSDictionaryResultType is used on a fetch request and a selected column is present on a joined table, an "ambiguous column name: columnName" error results. The columns should be prefixed with tableName.columnName to avoid this ambiguity.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant