Amplify-ios: SQL statement "root"."postUserIdId" = ?" should be "root"."userId" = ?"

Created on 3 Jun 2020  路  2Comments  路  Source: aws-amplify/amplify-ios

I have a separate but potentially related issue regarding DataStore. I have put a message out in discord https://discord.com/channels/705853757799399426/707328996995760179/717494199875797092 if you have a minute would you mind checking?

In summary, when I use self.users?.posts?.count the output fails (I have tested and the data exists online 1:m posts

Here is the output:

`no such column: root.postUserIdId in "select
  "root"."id" as "id", "root"."createdTimestamp" as "createdTimestamp", "root"."imageUrl" as "imageUrl",
  "root"."text" as "text", "root"."updatedTimestamp" as "updatedTimestamp", "root"."userId" as "userId"
from Post as root
where 1 = 1
  and "root"."postUserIdId" = ?"
Fatal error: The operation couldn鈥檛 be completed. (SQLite.Result error 0.): file /Users/development/Documents/Development/AWS/FullStackSocial/Pods/Amplify/Amplify/Categories/DataStore/Model/Collection/List+LazyLoad.swift, line 96
2020-06-02 22:47:50.150875+0100 FullStackSocial[45576:1966345] Fatal error: The operation couldn鈥檛 be completed. (SQLite.Result error 0.): file /Users/development/Documents/Development/AWS/FullStackSocial/Pods/Amplify/Amplify/Categories/DataStore/Model/Collection/List+LazyLoad.swift, line 96`

Model (note that I added userId and no connection to Post):

`type User @model {
  id: ID!
  fullName: String!
  emailAddress: String
  bio: String
  profileImageUrl: String
  isFollowing: Boolean
  following: [UserFollowing] @connection (keyName: "following", fields: ["id"])
  followers: [UserFollowers] @connection (keyName: "followers", fields: ["id"])
  isEditable: Boolean
  posts: [Post] @connection(keyName: "posts", fields: ["id"])
  createdTimestamp: Int!
  updatedTimestamp: Int
}

type UserFollowing @model @key(name: "following", fields:["userId"]) {
  id: ID!
  userId: ID!
}

type UserFollowers @model @key(name: "followers", fields:["userId"]) {
  id: ID!
  userId: ID!
}

type Post @model @key(name: "posts", fields:["userId", "createdTimestamp"], queryField: "postsByCreatedtimestamp" )  {
  id: ID!
  userId: ID!
  text: String
  imageUrl: String
  createdTimestamp: Int!
  updatedTimestamp: Int
}`

_Originally posted by @mickeysox in https://github.com/aws-amplify/amplify-ios/issues/483#issuecomment-637830265_

bug datastore duplicate

All 2 comments

from @drochetti
"it seems to be a bug, in the SQL statement where it says and "root"."postUserIdId" = ?" it should be and "root"."userId" = ?" as per your schema"

https://discord.com/channels/705853757799399426/707328996995760179/717500699419607201

I can confirm this is a duplicate of #512

Was this page helpful?
0 / 5 - 0 ratings