Open elersong opened 3 months ago
@Collection()
class Band {
id: string;
@DocumentReference()
artist: Reference<Artist>;
}
// Creating a reference with a string
getRepository(Band).create({
id: 'fireorm rocks!',
artist: '/artists/wovalle'
});
// Creating a reference with an object const artist = new Artist(); artist.id = 'new-artist'; artist.name = 'New Artist';
getRepository(Band).create({ id: 'fireorm rocks!', artist: setReference(artist), });
### Proposed API Changes
1. Reference Type and Decorator:
- Introduce a generic Reference<T> type to handle document references.
- Use @DocumentReference() decorator to mark properties as references.
```typescript
@Collection()
class Band {
id: string;
@DocumentReference()
artist: Reference<Artist>;
}
Handling Reference Creation:
// Example with reference path as string
getRepository(Band).create({
id: 'fireorm rocks!',
artist: '/artists/wovalle'
});
// Example with reference object const artist = new Artist(); artist.id = 'new-artist'; artist.name = 'New Artist';
getRepository(Band).create({ id: 'fireorm rocks!', artist: setReference(artist), });
3. Adding Path Information to Entities:
- Introduce a getPath method to entities for easy access to their document paths.
- Ensure that the path is stored and accessible within the entity's instance.
4. Reference Validation:
- Implement validation logic for reference paths based on Firebase's guidelines, ensuring paths are non-empty strings without double slashes.
5. TypeScript Compatibility:
- Ensure the proposed changes are compatible with TypeScript's type checking and autocomplete features.
- Use a generic approach to allow properties to be of type T or string while maintaining type safety.
Description
Fireorm currently does not support creating entities with referenced properties directly. Users need a way to reference other collections when creating new documents, such as referencing a
Produtor
from within aProdutorDadosAdicionais
entity.Steps to Reproduce
Produtor
class and aProdutorDadosAdicionais
class, withProdutorDadosAdicionais
having a property referencingProdutor
.ProdutorDadosAdicionais
document with a reference to an existingProdutor
document.Expected Behavior
Ability to create documents with referenced properties that correctly store document references in Firestore.
Actual Behavior
Currently, there is no straightforward way to set referenced properties, leading to workarounds or potential bugs with deserialization/serialization of Firestore entities.
Acceptance Criteria
getRef/getPath
function to entities for easy access to document paths.Additional Context
produtorId
andprodutorNome
properties.Reference<T>
type and@DocumentReference()
decorator.Original