Querying a "Following" Table

I have a simple “Following” table which, along with the boiler plate fields, has a “toUser” and “fromUser”, which are pointers to the User table.

I am trying to query the Following table for users that have “fromUser” matching the current user. I’m using the following query (have force unwrapped for brevity), which is loosely based on the SnapCat code:

let user = User.current!
let followings = try await Following.query("fromUser" == user.objectId).find()

In the “Following” table there is an entry in the “fromUser” that has the correct objectId, but the query returns 0 values.

Any help would be appreciated!

Both field pointer . You should change like this fromUser.objectId

So I tried:

let followings = try await Following.query("fromUser.objectId" == user.objectId).find()

but still returned 0 results

So the solution was to check for the entire user object, not just the objectId on the user:

let followings = try await Following.query("fromUser" == user).find()

This is not good practise, you are checking pointers. I think This is increase query count in the background