github.com/weaviate/weaviate@v1.24.6/usecases/objects/references.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package objects
    13  
    14  import (
    15  	"context"
    16  
    17  	"github.com/go-openapi/strfmt"
    18  	"github.com/weaviate/weaviate/entities/models"
    19  	"github.com/weaviate/weaviate/entities/schema"
    20  	"github.com/weaviate/weaviate/entities/schema/crossref"
    21  )
    22  
    23  func (m *Manager) autodetectToClass(ctx context.Context, principal *models.Principal, fromClass, fromProperty string, beaconRef *crossref.Ref) (strfmt.URI, strfmt.URI, bool, *Error) {
    24  	// autodetect to class from schema if not part of reference
    25  	class, err := m.schemaManager.GetClass(ctx, principal, fromClass)
    26  	if err != nil {
    27  		return "", "", false, &Error{"cannot get class", StatusInternalServerError, err}
    28  	}
    29  	prop, err := schema.GetPropertyByName(class, schema.LowercaseFirstLetter(fromProperty))
    30  	if err != nil {
    31  		return "", "", false, &Error{"cannot get property", StatusInternalServerError, err}
    32  	}
    33  	if len(prop.DataType) > 1 {
    34  		return "", "", false, nil // can't autodetect for multi target
    35  	}
    36  
    37  	toClass := prop.DataType[0] // datatype is the name of the class that is referenced
    38  	toBeacon := crossref.NewLocalhost(toClass, beaconRef.TargetID).String()
    39  
    40  	return strfmt.URI(toClass), strfmt.URI(toBeacon), true, nil
    41  }