Fix broken filtering through discriminator

This commit is contained in:
George Suntres
2026-04-17 20:46:00 -04:00
parent 99b36e577e
commit 7599b8b856
7 changed files with 30 additions and 11 deletions

View File

@@ -11,6 +11,10 @@ import (
func (c *MongoClient) DiscriminatorCheckAndApplyToData(ctx context.Context, name string, data map[string]any) error {
cdef, ok := c.Registry[name]
if ok && cdef.Discriminator != nil {
if data == nil {
data = map[string]any{}
}
log.Printf("Discriminator found for %s; will use it", name)
// get from context
@@ -30,6 +34,10 @@ func (c *MongoClient) DiscriminatorCheckAndApplyToData(ctx context.Context, name
func (c *MongoClient) DiscriminatorCheckAndApplyToFilter(ctx context.Context, name string, filter bson.M) error {
cdef, ok := c.Registry[name]
if ok && cdef.Discriminator != nil {
if filter == nil {
filter = bson.M{}
}
log.Printf("Discriminator found for %s; will use it", name)
// get from context