Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amplify DataStore: many-to-many join table not syncing when using selective sync #5454

Open
2 of 14 tasks
stephenjen opened this issue Sep 13, 2024 · 8 comments
Open
2 of 14 tasks
Labels
datastore Issues related to the DataStore Category pending-maintainer-response Pending response from a maintainer of this repository pending-triage This issue is in the backlog of issues to triage to-be-reproduced Issues that have not been reproduced yet, but have reproduction steps provided

Comments

@stephenjen
Copy link

Description

I'm experiencing an issue with Amplify DataStore in a Flutter application. The main models (Share and OperationMode) are syncing correctly, but the automatically generated join table for a many-to-many relationship (ShareOperationMode) is not syncing to the device.

Here is the schema:

type Share @model @auth(rules: [{ allow: private, ownerField: "pOwner" }]) {
  id: ID!
  // ... other fields ...
  operationModes: [OperationMode] @manyToMany(relationName: "ShareOperationMode")
  pOwner: String!
}

type OperationMode @model @auth(rules: [{allow: private}]) {
  id: ID!
  // ... other fields ...
  shares: [Share] @manyToMany(relationName: "ShareOperationMode")
}

Here is the syncExpressions:

final syncExpressions = [
  DataStoreSyncExpression(Share.classType, 
    () => Share.POWNER.eq(prefs.getString('userId') ?? '')
      .or(Share.POWNER.isOneOf(prefs.getStringList('friendIds') ?? []))
  ),
  DataStoreSyncExpression(OperationMode.classType, () => QueryPredicate.all),
];

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Notifications (Push)
  • Storage

Steps to Reproduce

  1. Add selective sync to Share model
  2. Install app
  3. Wait for sync to complete. After initial syncing, I run DataStore.close() to stop so sync expression can be loaded again to load records owned by user's friends
  4. Share and OperationMode sync correctly, but ShareOperationMode does not sync and is left with zero records.

Screenshots

No response

Platforms

  • iOS
  • Android
  • Web
  • macOS
  • Windows
  • Linux

Flutter Version

3.24.0

Amplify Flutter Version

2.4.1

Deployment Method

Amplify CLI (Gen 1)

Schema

No response

@github-actions github-actions bot added pending-triage This issue is in the backlog of issues to triage pending-maintainer-response Pending response from a maintainer of this repository labels Sep 13, 2024
@tyllark
Copy link
Member

tyllark commented Sep 13, 2024

Hi @stephenjen, thank you for submitting this issue. We will take a look at this issue and get back to you when we have any updates or questions.

@github-actions github-actions bot removed the pending-maintainer-response Pending response from a maintainer of this repository label Sep 13, 2024
@Equartey Equartey added to-be-reproduced Issues that have not been reproduced yet, but have reproduction steps provided datastore Issues related to the DataStore Category labels Sep 16, 2024
@stephenjen
Copy link
Author

An update - I'm able to sync ShareOperationMode items for the owner but not for the owner's friends, even through I am able to sync owner's friends' Share items, which has a sync expression of Share.POWNER.isOneOf(prefs.getStringList('friendIds') ?? []).

@github-actions github-actions bot added the pending-maintainer-response Pending response from a maintainer of this repository label Sep 16, 2024
@stephenjen
Copy link
Author

An update - It works properly when I clear() as opposed to stop() before restarting DataStore to reevaluate sync expressions. Please make this work for stop() too, as having to wait for a clear() is quite impractical outside of the initial sync when users first install and get the app going.

Maybe there's a better way for me. My current use case: users can find and add friends in the app, and when they do, they can also see items owned by their friends. Currently I reevaluate sync expressions to enable this functionality, but is there a way to set up my schema so I can 1) accomplish the functionality I just described; and 2) do so without users having to carry around both their friends' and non-friends' items?

@stephenjen
Copy link
Author

Any updates?

@khatruong2009
Copy link
Member

@stephenjen, do you get this problem for Android too or is this only an issue you're having with iOS?

@github-actions github-actions bot removed the pending-maintainer-response Pending response from a maintainer of this repository label Sep 23, 2024
@khatruong2009 khatruong2009 added the pending-community-response Pending response from the issue opener or other community members label Sep 23, 2024
@stephenjen
Copy link
Author

I'm only developing for iOS, so can only speak to it not working in iOS

@github-actions github-actions bot added pending-maintainer-response Pending response from a maintainer of this repository and removed pending-community-response Pending response from the issue opener or other community members labels Sep 24, 2024
@khatruong2009
Copy link
Member

Hi @stephenjen, isOneOf isn't in our list of supported predicates. As an alternative to that, you could building a predicate group of or predicates that checks if POWNER is equal to each item of the prefs.getStringList('friendIds')

@github-actions github-actions bot removed the pending-maintainer-response Pending response from a maintainer of this repository label Sep 25, 2024
@khatruong2009 khatruong2009 added the pending-community-response Pending response from the issue opener or other community members label Sep 25, 2024
@stephenjen
Copy link
Author

@khatruong2009 yes, that is a custom extension that essentially creates a series of .or() predicates.

I'm not sure this is the issue as this custom extension works for the Share and other models.

The issue seems to be when the sync expressions is reevaluated for Share, the automatically generated ShareOperationMode (the many to many join model) isn't updated.

@github-actions github-actions bot added pending-maintainer-response Pending response from a maintainer of this repository and removed pending-community-response Pending response from the issue opener or other community members labels Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datastore Issues related to the DataStore Category pending-maintainer-response Pending response from a maintainer of this repository pending-triage This issue is in the backlog of issues to triage to-be-reproduced Issues that have not been reproduced yet, but have reproduction steps provided
Projects
None yet
Development

No branches or pull requests

4 participants