orientechnologies / pyorient

OrientDB driver for Python that uses the binary protocol.
Apache License 2.0
119 stars 38 forks source link

Using `record_create` with an embedded class. #33

Closed backwardspy closed 1 year ago

backwardspy commented 5 years ago

Let's say I have two classes: User and Profile. Let's say I have linked Profile to User as follows: CREATE PROPERTY User.profile EMBEDDED Profile (MANDATORY TRUE, NOTNULL TRUE)

How can I use record_create to insert a new User + Profile?

I have tried the following:

client.record_create(-1, {
    "@User": {
        "id": "abc123",
        "profile": {
            "name": "John Doe",
        }
    }
})
client.record_create(-1, {
    "@User": {
        "id": "abc123",
        "profile": {
            "@Profile": {
                "name": "John Doe",
            }
        }
    }
})

In both cases, I get errors like the following:

pyorient.exceptions.PyOrientCommandException: com.orientechnologies.orient.core.exception.OValidationException - The field 'User.profile' is mandatory, but not found on record: Profile{"name":John Doe}
pyorient.exceptions.PyOrientCommandException: com.orientechnologies.orient.core.exception.OValidationException - The field 'User.profile' is mandatory, but not found on record: Profile{Profile":[1]}

I couldn't find anything in the documentation or elsewhere showing the correct syntax for inserting an embedded record.

Thanks!