Cannot figure out how to use cross-references

Description

My schema is configured as follows:

[
            "class" => "SearchMediaTranscript",
            "vectorizer" => "none",
            "properties" => [
                [
                    "name" => "media_id",
                    "dataType" => ["int"]
                ],
                [
                    "name" => "text",
                    "dataType" => ["text"]
                ],
                [
                    "name" => "start_time",
                    "dataType" => ["number"]
                ],
                [
                    "name" => "end_time",
                    "dataType" => ["number"]
                ]
            ],
            "references" => [
                [
                    "name" => "hasMedia",
                    "target_collection" => "SearchMedia"
                ]
            ]
        ]

I’m using the RESTful api directly, no sdk really (well, i’m using an unofficial php thing but it’s just rest)

That schema successfully creates but when I check v1/schema/SearchMediaTranscript I don’t see any references defined, but I’m not sure if it’s supposed to.

The issue is when I load data into this schema I add the reference like this:
“references” => [“hasMedia” => $searchMedia->getId()] and this doesn’t throw any errors. However when I try to include this in my graphql query I get the following error:

query Get {
    Get {
        SearchMediaTranscript {
            end_time
            media_id
            start_time
            text
            hasMedia {
                ... on SearchMedia {
                    title
                }
            }
        }
    }
}

“message”: “Cannot query field "hasMedia" on type "SearchMediaTranscript".”,

Server Setup Information

  • Weaviate Server Version: 1.24.12
  • Deployment Method: docker
  • Multi Node? Number of Running Nodes: single node
  • Client Language and Version: postman graphql

Ah, ok, so I figured out my mistake

apparently the “references” field is for attaching the cross refs,

to define the cross reference you need to add is as a parameter to the original schema:

like so:

[
    "name" => "hasTranscript",
    "dataType" => ["SearchMediaTranscript"]
]

Where SearchMediaTranscript is a schema and hasTranscript is the cross-ref

1 Like

hi @maddios !!

Glad you figure it our AND shared your findings.

Thanks, we really appreciate this!