How to fill-up (update) a map (list) array field from another collection, using actions

I'm new in Flutterflow and trying my first project.

I have a collection called Igrejas that contains a map (list) array field structure called membros.

I need to update an Igrejas document filling-up this membros array structure using the data from another collection documents with same layout fields, called TempMembros.

I'd like to use button called actions to achieve this.

I have tried to use query based list views and action queries followed by update documents, but in the action update document, I got stuck, because there is always another option listto select from like (first items, item at index..., and so on).

Any clues to do this ?

Thanks in advance.

Roquevalder.

Button action created

After several test and tries, I have managed a way to contour the problem.

First of all, my misunderstanding was about data structures, specially in relation between the membrosTemp collection structure and the membros structure inside the Igrejas collection, although both have the same sub-fields(nome, grupo, situacao, categoria and sexo).

My contour solution was:

Igrejas collection (the one to be updated):

codigrej - string
igreja - string

membros (map structure list) with:

-nome - string
-grupo - string
-situacao - string
-categoria - string
-sexo - string

TempMembros collection (to one to provide data to update):

nome - string
grupo - string
situacao - string
categoria - string
sexo - string
  1. In a page with 2 containers (1 for Igrejas collection and other for TempMembros collections), both with related queries (the specific Igrejas query, resulting the document to be updated and all the documents for the TempMembros collection query), I have inserted a button for the actions.
  2. Then, I've used a loop action, controlled by a contador (counter) app state.
  3. inside this loop I've inserted an action to update the igrejas document reference, in field (structure) membros, with the option to Add to Set, and the sub-option Set Individual Fields. On each of the 5 sub-fields, use the TempMembros documents, selecting an item at Index option, specific Item, and passing the contador (counter) as value. After that, get Document Property and selecting the suitable TempMembros subfield related to the one I am setting up.

The main issue of this contour solution is too many update calls to Firebase, as I am issuing one update action on Igrejas collection document for each one of the membros item added, what in my opinion should not be necessary, as membros is just a structure inside the Igrejas document.

I'd prefer a way to add all the TemoMembros record in some app state variable, let's say, membrosCarga (some list type variable), and then update just once the Igrejas document, making membros structure = membrosCarga. Unfortunately, I could not accomplish that, after dozens of tries.

Any suggestions are very appreciated.

Action reading TempMembros Collection

Action reading Igrejas Collection

Action trying to update Collection igrejas from Collection TempMembros output

Upvotes: 0

Views: 24

Answers (0)

Related Questions