How to write predicate to express not-in for compound index?

For example:

SELECT * 
FROM accounts 
WHERE (platform, innerID) NOT IN (
    ('platform_value1', 'innerID_value1'),
    ('platform_value2', 'innerID_value2'),
    ...
);

this is hard to use Swift Predicate:

    func _fetchAccountNotIn(_ scope: [Account]) throws -> [Account] {
        let scope = scope.map{ ($0.platform, $0.innerID) }
        return try fetch(.init(predicate: #Predicate<Account> { !scope.contains(($0.platform, $0.innerID)) }))
    }

shows compiler error: Cannot convert value of type '(String, String)' to expected argument type '((String, String)) throws -> Bool'

Account definition:

@Model
public final class Account {
    
    #Unique<Account>([\.platform, \.innerID])
    #Index<Account>([\.platform, \.innerID])

    @Attribute(.preserveValueOnDeletion)
    public private(set) var platform    : String
    
    @Attribute(.preserveValueOnDeletion)
    public private(set) var innerID     : String
}
Answered by joadan in 801493022

You have a unique requirement on the attribute pair so there is only one Account object that has a given combination of the two attribute.

Doesn’t that mean that you can skip the tuple and instead use the id property in your code? That is still use map and the same predicate but with id (or persistentModelId) instead of the tuple?

Accepted Answer

You have a unique requirement on the attribute pair so there is only one Account object that has a given combination of the two attribute.

Doesn’t that mean that you can skip the tuple and instead use the id property in your code? That is still use map and the same predicate but with id (or persistentModelId) instead of the tuple?

How to write predicate to express not-in for compound index?
 
 
Q