Skip to content

Firebase.push failed: first argument contains an invalid key ($key) #790

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

Closed
renansuzin opened this issue Jan 23, 2017 · 4 comments
Closed

Comments

@renansuzin
Copy link

Version info

Angular: 2.2.1

Firebase: 3.6.5

AngularFire: 2.0.0

Other (e.g. Ionic/Cordova, Node, browser, operating system):

Ionic Framework: 2.0.0-rc.5
Ionic Native: 2.2.11
Ionic App Scripts: 1.0.0
Angular Core: 2.2.1
Angular Compiler CLI: 2.2.1
Node: 6.9.3
OS Platform: Windows 10
Navigator Platform: Win32
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36

Debug output

Runtime Error
Error in ./FormTurmaPage class FormTurmaPage - caused by: Firebase.push failed: first argument contains an invalid key ($key) in property 'escola1.turmas.alunos:.0'. Keys must be non-empty strings and can't contain ".", "#", "$", "/", "[", or "]"

** Screenshots **

image

image

image

image

I'm trying to push a array(alunosTurma[]) of objects(aluno) to a new Firebase item(turma). In my code a get all the alunos and store in a firebaseobservablelist, in the alunosTurma list i store some aluno's objects and when a try to push the alunos list from a new Turma object on firebase i get the error.

@byrondover
Copy link
Contributor

@renansuzin This should be addressed by #787.

See #197 for a workaround, and #302 for more context / details. As a side note, nesting a list of alunos within turmas may be a bit of an anti-pattern, and you might want to consider instead using separate calls to retrieve alunos, as necessary. :bowtie:

https://firebase.google.com/docs/database/web/structure-data#avoid_nesting_data

@renansuzin
Copy link
Author

renansuzin commented Jan 24, 2017

@byrondover

Thanks for response, in this case a need to list all of alunos to user select and save some in the turma, i dont are saving all the alunos in the turma only the selected by user, im using the alunosTurma list to store the selected alunos and when i try to push the alunosTurma to turma i get the error.

The data scructure is like this:

alunos = all the alunos for the user select
alunosTurma = alunos list to store the selected alunos by user
turma = a turma object, it need to have a list of alunos

@byrondover
Copy link
Contributor

Fair enough.

You may want to consider implementing a lookup collection in Firebase for students belonging to classrooms (e.g. turmaAlunos), but it depends on your use case and query patterns. @davideast has a great video about this on YouTube: https://youtu.be/ran_Ylug7AE.

Feel free to ping me on Gitter if you'd like to discuss further!

https://gitter.im/angular/angularfire2

@renansuzin
Copy link
Author

Thanks for your help @byrondover, i'm going to watch the video and follow the @davideast instructions to structure the data of my app, i already joined in the gitter group, thanks for invite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants