-
Notifications
You must be signed in to change notification settings - Fork 2.2k
idField on valueChanges doesn't work as expected. #2753
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
Comments
This issue does not seem to follow the issue template. Make sure you provide all the required information. |
But the document reference has an ID (that you queried to get the reference)... so why wouldn't it return the ID you requested? |
Because if the document doesn't actually exist, you would expect it to return nothing. Think of it this way, if you don't provide idField and the document doesn't exist, the observable returned emits Long story short, this is about the intended behaviour of idField. If it is to add the id of a document to the returned data, then it makes sense that if there is no data, the id field shouldn't be returned either. Do you understand what I'm saying, or is my explanation just going round in circles. I could try and make some examples to show what I mean if you want? |
I feel like returning the an object (with the id field) implies that the document exists. If others don't feel this is the case, maybe an extra option could be added to specify this. This option would also prevent unexpected changes if people are used to the current behaviour. |
Addressed in v7 api. |
Version info
Angular: 11
Firebase: 8
AngularFire: 6
Other: MacOS Big Sur
Issue
When you call valueChanges on a document you know doesn't exist, it emits undefined. However if you specify idField, for example, as id, then it will return an object with the field id. I expected that it would still return undefined. It returning causes problems, as the object then isn't in the shape you expect (if you specify a type of the result) but also you get a result when a document doesn't actually exist.
I think the issue is simply in the valueChanges function:
As you can see, if payload.data() is undefined, this function will create an object with id field. I think a simple fix would be:
I don't actually know much about the underlying firebase apis, but I'm assuming that payload.data() is undefined if there is no document.
The text was updated successfully, but these errors were encountered: