Jas1997
Jas1997

Reputation: 99

Is it possible for Firebase objects to point to other Firebase objects

Say that I have a Firebase user who can subscribe to magazines. Currently I save the subscribed magazine reference keys from Firebase locally on the user's device. Is there a way for the Firebase magazine object to be created as a node under the user object on Firebase, when I have the database key that points to the specific magazine object? So when the magazine object is updated, the magazine object under the user will also be updated. Essentially the magazine object under the user is pointing to the actual magazine object.

Upvotes: 0

Views: 93

Answers (1)

vzsg
vzsg

Reputation: 2896

As of right now, this is not possible automatically, as there is no concept of "linking" two nodes together. Not all is lost though, you can work around this limitation in at least two ways:

  1. If you choose to duplicate the magazine data under every user, consider making the updates eventually consistent. Use a custom server application to first update the "global" node, then update every subscribed user's feed in a delayed fashion.
    This strategy is friendlier towards the client apps, but makes updates a magnitude more complex.
  2. Or don't copy the magazine data into the user nodes, store just the IDs; and let the client applications cherry pick magazines one-by-one with value subscriptions.
    This makes updating a magazine trivial at the expense of client complexity.

Upvotes: 1

Related Questions