Repository: marcosschroh/dataclasses-avroschema

Issue:
Nested metadata not respected
**Describe the bug**
If I override a `schema_name` attribute for a class that's used as a field, that schema_name isn't respected.

**To Reproduce**
```python
from dataclasses_avroschema import AvroModel
from dataclasses import dataclass

@dataclass
class MyClass(AvroModel):
    field_1: str
    class Meta:
        schema_name = "custom_class" # <-- this is not respected
class MySecondClass(AvroModel):
    field_2: MyClass
    class Meta:
        schema_name = "custom_name"
        
MySecondClass.avro_schema_to_python()
```

This outputs

```python
{'type': 'record',
 'name': 'custom_name',
 'fields': [{'name': 'field_2',
   'type': {'type': 'record',
    'name': 'MyClass', # <-- this line is wrong
    'fields': [{'name': 'field_1', 'type': 'string'}],}}],
}
```

**Expected behavior**

I would expect
```python
{'type': 'record',
 'name': 'custom_name',
 'fields': [{'name': 'field_2',
   'type': {'type': 'record',
    'name': 'custom_class', # This is the important line
    'fields': [{'name': 'field_1', 'type': 'string'}],}}],
}
```


Comments:

Patch:
diff --git a/dataclasses_avroschema/fields.py b/dataclasses_avroschema/fields.py
index bb973af..8ec1397 100644
--- a/dataclasses_avroschema/fields.py
+++ b/dataclasses_avroschema/fields.py
@@ -685,8 +685,16 @@ class UUIDField(LogicalTypeField):
 @dataclasses.dataclass
 class RecordField(BaseField):
     def get_avro_type(self) -> typing.Union[typing.List, typing.Dict]:
-        alias = self.parent.metadata.get_alias(self.name) or self.model_metadata.get_alias(self.name)  # type: ignore
-        name = alias or self.type.__name__
+        meta = getattr(self.type, "Meta", None)
+        metadata = utils.SchemaMetadata.create(meta)
+
+        alias = self.parent.metadata.get_alias_nested_items(self.name) or metadata.get_alias_nested_items(self.name)  # type: ignore  # noqa E501
+
+        # The priority for the schema name
+        # 1. Check if the schema_name is present in the Meta class of own model
+        # 2. Check if exists an alias_nested_items in parent class or Meta class of own model
+        # 3. Use the default class Name (self.type.__name__)
+        name = metadata.schema_name or alias or self.type.__name__
 
         if not self.exist_type():
             user_defined_type = utils.UserDefinedType(name=name, type=self.type)
@@ -697,9 +705,6 @@ class RecordField(BaseField):
             record_type = self.type.avro_schema_to_python(root=self.parent)
             record_type["name"] = name
         else:
-            meta = getattr(self.type, "Meta", None)
-            metadata = utils.SchemaMetadata.create(meta)
-
             if metadata.namespace is None:
                 raise NameSpaceRequiredException(field_type=self.type, field_name=self.name)
             record_type = f"{metadata.namespace}.{name}"
diff --git a/dataclasses_avroschema/utils.py b/dataclasses_avroschema/utils.py
index 606cb63..0d3722f 100644
--- a/dataclasses_avroschema/utils.py
+++ b/dataclasses_avroschema/utils.py
@@ -90,7 +90,7 @@ class SchemaMetadata:
             alias_nested_items=getattr(klass, "alias_nested_items", {}),
         )
 
-    def get_alias(self, name: str) -> typing.Optional[str]:
+    def get_alias_nested_items(self, name: str) -> typing.Optional[str]:
         return self.alias_nested_items.get(name)
 
 


Test patch:
diff --git a/tests/schemas/test_schema.py b/tests/schemas/test_schema.py
index b9252ee..d1f6c20 100644
--- a/tests/schemas/test_schema.py
+++ b/tests/schemas/test_schema.py
@@ -151,6 +151,24 @@ def test_get_fields():
     assert Parent.fake()
 
 
+def test_schema_name_from_relationship():
+    @dataclass
+    class MyClass(AvroModel):
+        field_1: str
+
+        class Meta:
+            schema_name = "custom_class"
+
+    class MySecondClass(AvroModel):
+        field_2: MyClass
+
+        class Meta:
+            schema_name = "custom_name"
+
+    schema = MySecondClass.avro_schema_to_python()
+    assert schema["fields"][0]["type"]["name"] == "custom_class"
+
+
 def test_validate():
     @dataclass
     class User(AvroModel):