Skip to content

How to create a new document with a reference? #118

Open
@lucasdidur

Description

@lucasdidur

Hello, how can I create a new ProdutorDadosAdicionais with a referencied property produtor of Produtor class?

@Collection()
export class Produtor {
    id: string
    nome?: string;
}

@Collection()
export class ProdutorDadosAdicionais {
    id: string;
    nome: string;
    produtor: Produtor;
}

I tried this, but no gave me a error:

  | Error: Value for argument "data" is not a valid Firestore document. Couldn't serialize object of type "Produtor" (found in field produtor). Firestore doesn't support JavaScript objects with custom prototypes (i.e. objects that were created via the "new" operator). -- | --   | at Object.validateUserInput (C:\Users\lucas.didur\Desktop\Nova pasta\functions\node_modules\@Google-Cloud\firestore\build\src\serializer.js:311:15)   | at validateDocumentData (C:\Users\lucas.didur\Desktop\Nova pasta\functions\node_modules\@Google-Cloud\firestore\build\src\write-batch.js:611:22)   | at WriteBatch.set (C:\Users\lucas.didur\Desktop\Nova pasta\functions\node_modules\@Google-Cloud\firestore\build\src\write-batch.js:232:9)   | at DocumentReference.set (C:\Users\lucas.didur\Desktop\Nova pasta\functions\node_modules\@Google-Cloud\firestore\build\src\reference.js:334:14)   | at BaseFirestoreRepository. (C:\Users\lucas.didur\Desktop\Nova pasta\functions\node_modules\fireorm\lib\src\BaseFirestoreRepository.js:109:50)   | at step (C:\Users\lucas.didur\Desktop\Nova pasta\functions\node_modules\fireorm\lib\src\BaseFirestoreRepository.js:46:23)   | at Object.next (C:\Users\lucas.didur\Desktop\Nova pasta\functions\node_modules\fireorm\lib\src\BaseFirestoreRepository.js:27:53)   | at fulfilled (C:\Users\lucas.didur\Desktop\Nova pasta\functions\node_modules\fireorm\lib\src\BaseFirestoreRepository.js:18:58)   | at   | at process._tickCallback (internal/process/next_tick.js:189:7)
let doc = new ProdutorDadosAdicionais();
doc.nome = "Teste";
doc.produtor = await prod.findById("ITXaj7Gss5dt1cOpT0qf");

await repo.create(doc);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions