# Does Weaviate allow classes to have self-referential properties?

**URL:** <https://forum.weaviate.io/t/does-weaviate-allow-classes-to-have-self-referential-properties/521>\
**Category:** Support\
**Created:** [August 10, 2023, 12:54pm UTC](https://forum.weaviate.io/t/does-weaviate-allow-classes-to-have-self-referential-properties/521 "2023-08-10T12:54:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gsVAM](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/gsvam/32/361_2.png) [@gsVAM](https://forum.weaviate.io/u/gsVAM)\
**Post date:** [August 10, 2023, 12:54pm UTC](https://forum.weaviate.io/t/does-weaviate-allow-classes-to-have-self-referential-properties/521/1 "2023-08-10T12:54:45Z")

</div>

Question that I am very surprised I cannot find an answer to –

Does Weaviate allow a class to have a property that is its own class (i.e. a self-reference). For example I can have a document that has a property that references another object of the document class. This is of course a common feature in other document databases. Is it possible with Weaviate? If yes, are there any concerns I should have with implementing it? e.g.

```auto
{
  "class": "Document",
  "properties": [
    {
      "name": "title",
      "dataType": ["string"]
    },
    {
      "name": "parentDocument",
      "dataType": ["Document"]
    }
  ]
}

```

Thank you!

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [August 11, 2023, 1:18am UTC](https://forum.weaviate.io/t/does-weaviate-allow-classes-to-have-self-referential-properties/521/2 "2023-08-11T01:18:47Z")

</div>

Hi @gsVAM !! Welcome to our community!!

That’s a really good question, which I don’t have the answer. Yet. 😅

I’ll ping our core team about it.

Thanks for asking!

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [August 12, 2023, 10:52pm UTC](https://forum.weaviate.io/t/does-weaviate-allow-classes-to-have-self-referential-properties/521/3 "2023-08-12T22:52:28Z")

</div>

Hi @gsVAM! Here it is:

```python
class_obj = {
  "class": "Document",
  "properties": [
    {
      "name": "title",
      "dataType": ["string"]
    },
    {
      "name": "parentDocument",
      "dataType": ["Document"]
    }
  ]
}
# lets create our class
client.schema.create_class(class_obj)
# lets predefine our uuids
d1_uuid = weaviate.util.generate_uuid5("document1")
d2_uuid = weaviate.util.generate_uuid5("document2")
print("document1", d1_uuid)
print("document2", d2_uuid)
# create objects
document1 = client.data_object.create({"title":"Document 1"}, "Document", d1_uuid)
document2 = client.data_object.create({"title":"Document 2"}, "Document", d2_uuid)
# add references
client.data_object.reference.add(
        from_class_name="Document",
        from_uuid=d1_uuid,
        from_property_name="parentDocument",
        to_class_name="Document",
        to_uuid=d2_uuid        
    )

```

now to query this self referential property:

```python
client.query.get("Document", ["title", "parentDocument{...on Document{title}}"]).do()

```

the resulting Graphql:

```graphql
{
  Get {
    Document {
      title
      parentDocument {
        ... on Document {
          title
        }
      }
      _additional {
        id
      }
    }
  }
}

```

and finally the json response:

```json
{'data': {'Get': {'Document': [{'_additional': {'id': '41fdaad0-e1b2-5d0e-a486-b9b519029264'},
     'parentDocument': None,
     'title': 'Document 2'},
    {'_additional': {'id': 'd895dd7c-deb6-5d5f-8129-379990b2f866'},
     'parentDocument': [{'title': 'Document 2'}],
     'title': 'Document 1'}]}}}

```

This is the documentation where it states how to add those references 🙂

> **[Cross-references | Weaviate - vector database](https://weaviate.io/developers/weaviate/manage-data/cross-references#add-a-one-way-cross-reference-property)**
>
> Overview
