-
We have Integrify setup with one collection to try it out and I think one misconception was that Integrify would copy over fields when a new document was created on the target collection. Example: export const replicateUsers = integrify({
rule: "REPLICATE_ATTRIBUTES",
source: {
collection: "users",
},
targets: [
{
collection: "projects",
foreignKey: "user.id",
attributeMapping: {
username: "user.username",
avatar: "user.avatar",
},
},
],
}); Are these attributes only replicated when the master collection fields are updated? Are we still responsible for creating the initial payload with intended replicated attributes? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
@narkeeso thanks for trying out Yes, you are correct. The attributes are replicated from source to target only upon updating of the source document. The target document(s) need to exist for Fundamentally, This is best suited for so called "one-to-many" relationships as explained in the introductory blog post. The reason for this is that A workaround maybe to create a Firestore HTH Edit: Created issue to try and clarify this point in the docs: #78 |
Beta Was this translation helpful? Give feedback.
@narkeeso thanks for trying out
integrify
!Yes, you are correct. The attributes are replicated from source to target only upon updating of the source document. The target document(s) need to exist for
integrify
to modify them.Fundamentally,
REPLICATE_ATTRIBUTES
creates a FirestoreonUpdate
trigger, which is only called when a document exists and its value is changed (see Cloud Firestore triggers docs).This is best suited for so called "one-to-many" relationships as explained in the introductory blog post.
The reason for this is that
integrify
cannot predict how many target documents to create every time a new source document is created. In your example, every time a user document is cre…