# The schema validation does not throw an error for a relation configuration that seems to be wrong to me. Correct behavior?

**URL:** <https://forum.typedb.com/t/the-schema-validation-does-not-throw-an-error-for-a-relation-configuration-that-seems-to-be-wrong-to-me-correct-behavior/475>\
**Category:** TypeDB\
**Tags:** schema-design\
**Created:** [22 March 2024 10:32 UTC](https://forum.typedb.com/t/the-schema-validation-does-not-throw-an-error-for-a-relation-configuration-that-seems-to-be-wrong-to-me-correct-behavior/475 "2024-03-22T10:32:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![c-lare](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@c-lare](https://forum.typedb.com/u/c-lare)\
**Post date:** [22 March 2024 10:32 UTC](https://forum.typedb.com/t/the-schema-validation-does-not-throw-an-error-for-a-relation-configuration-that-seems-to-be-wrong-to-me-correct-behavior/475/1 "2024-03-22T10:32:17Z")

</div>

Hi all,

I am testing several schema configurations and was interested whether a relation that inherits from another relation and overwrites one of the relates roles could a) still play a role in the parent relation and b) even play the role it itself overwrites. My schema initialization works without an error, so I was wondering whether this is actually intended behavior. I would be happy to hear your thoughts on this.

My schema:

```auto
define

credential sub attribute, abstract, value string;
credential-small sub credential, abstract, value string;
credential-smaller sub credential-small, value string;
full-name sub attribute, value string;
id sub attribute, abstract, value string;
email sub id, value string;
long-name sub id, value string;

impact sub relation,
    abstract,
    owns credential, 
    owns full-name,
    relates impactor, 
    relates impacted;

impact-small sub impact,
    owns credential-smaller as credential,
    relates impactor-small as impacted,
    plays impact:impacted;

```

---

<div class="post-metadata">

**Author:** ![jameswhiteside](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/jameswhiteside/32/94_2.png) [@jameswhiteside](https://forum.typedb.com/u/jameswhiteside)\
**Post date:** [22 March 2024 10:44 UTC](https://forum.typedb.com/t/the-schema-validation-does-not-throw-an-error-for-a-relation-configuration-that-seems-to-be-wrong-to-me-correct-behavior/475/2 "2024-03-22T10:44:05Z")

</div>

Hi, there is absolutely nothing wrong with this schema. Attribute ownerships and roles in TypeDB function as **interfaces**. This means that they can be independently implemented by any types, in keeping with **interface polymorphism**.

In this schema, you have three **role interfaces** :

- `impact:impactor`
- `impact:impacted`
- `impact-small:impactor-small`, a subtype of `impact:impacted`\*

Once these role interfaces are defined, they can be made to be played by _any_ entity or relation types, even the relations they are the interfaces of, using the `plays` keyword.  
You can read a bit more about the checks that take place during schema validation in the [docs](https://typedb.com/docs/learn/5-defining-schemas/5.5-schema-validation).

\* Are you sure this is correct? Did you mean to override the other role?

---

<div class="post-metadata">

**Author:** ![c-lare](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@c-lare](https://forum.typedb.com/u/c-lare)\
**Post date:** [22 March 2024 10:58 UTC](https://forum.typedb.com/t/the-schema-validation-does-not-throw-an-error-for-a-relation-configuration-that-seems-to-be-wrong-to-me-correct-behavior/475/3 "2024-03-22T10:58:26Z")

</div>

Amazing, this makes total sense. Thanks for the quick reply! 🙂

---

<div class="post-metadata">

**Author:** ![c-lare](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@c-lare](https://forum.typedb.com/u/c-lare)\
**Post date:** [22 March 2024 17:46 UTC](https://forum.typedb.com/t/the-schema-validation-does-not-throw-an-error-for-a-relation-configuration-that-seems-to-be-wrong-to-me-correct-behavior/475/4 "2024-03-22T17:46:34Z")

</div>

I hope you do not mind me asking another question. I was just wondering, when a child attribute of an abstract attribute, which is declared as @key in an abstract relation (or entity), overwrites this parent key attribute, will it also be a key? And does the same apply to “unique” attributes?

Here is an example:

```auto
define

credential sub attribute, abstract, value string;
credential-small sub credential, abstract, value string;
credential-smaller sub credential-small, value string;
name sub attribute, abstract, value string;
full-name sub name, value string;

impact sub relation,
    abstract,
    owns credential @key,
    owns name @unique, 
    relates impactor, 
    relates impacted;

impact-small sub impact,
    owns credential-smaller as credential,
    owns full-name as name,
    relates impactor-small as impacted,
    plays impact:impacted;

```

So, will “credential-smaller” also be a key attribute? And full-name unique?

---

<div class="post-metadata">

**Author:** ![jameswhiteside](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/jameswhiteside/32/94_2.png) [@jameswhiteside](https://forum.typedb.com/u/jameswhiteside)\
**Post date:** [22 March 2024 17:50 UTC](https://forum.typedb.com/t/the-schema-validation-does-not-throw-an-error-for-a-relation-configuration-that-seems-to-be-wrong-to-me-correct-behavior/475/5 "2024-03-22T17:50:04Z")

</div>

Great question! I believe the `key` and `unique` constraints should still apply. Perhaps @krishnan can verify?

---

<div class="post-metadata">

**Author:** ![krishnan](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/krishnan/32/36_2.png) [@krishnan](https://forum.typedb.com/u/krishnan)\
**Post date:** [25 March 2024 09:04 UTC](https://forum.typedb.com/t/the-schema-validation-does-not-throw-an-error-for-a-relation-configuration-that-seems-to-be-wrong-to-me-correct-behavior/475/6 "2024-03-25T09:04:39Z")

</div>

Yes. `credential-smaller` will be a key.  
When you override an ownership, the annotations `@key` and `@unique` are ‘inherited’.

So if you have

```auto
animal owns name @key;
dog sub animal, owns dog-name as name;
cat sub animal, owns cat-name as name;

```

Then dog will have dog-name as @key, and cat will have cat-name as @key - But it is possible that a dog and a cat can share a name. So `animal` does not really have name as @key.

---

<div class="post-metadata">

**Author:** ![c-lare](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@c-lare](https://forum.typedb.com/u/c-lare)\
**Post date:** [25 March 2024 11:35 UTC](https://forum.typedb.com/t/the-schema-validation-does-not-throw-an-error-for-a-relation-configuration-that-seems-to-be-wrong-to-me-correct-behavior/475/7 "2024-03-25T11:35:43Z")

</div>

Great, that makes perfect sense!
