fix bug with infinite relation auto extraction, finish initial relations docs
This commit is contained in:
@ -76,7 +76,9 @@ class ForeignKey(BaseField):
|
||||
|
||||
def register_relation(self, model: "Model", child: "Model") -> None:
|
||||
child_model_name = self.related_name or child.get_name()
|
||||
model._orm_relationship_manager.add_relation(model, child, child_model_name, virtual=self.virtual)
|
||||
model._orm_relationship_manager.add_relation(
|
||||
model, child, child_model_name, virtual=self.virtual
|
||||
)
|
||||
|
||||
def expand_relationship(
|
||||
self, value: Any, child: "Model"
|
||||
|
||||
@ -28,7 +28,11 @@ def parse_pydantic_field_from_model_fields(object_dict: dict) -> Dict[str, Tuple
|
||||
|
||||
|
||||
def register_relation_on_build(table_name: str, field: ForeignKey, name: str) -> None:
|
||||
child_relation_name = field.to.get_name(title=True) + "_" + (field.related_name or (name.lower() + "s"))
|
||||
child_relation_name = (
|
||||
field.to.get_name(title=True)
|
||||
+ "_"
|
||||
+ (field.related_name or (name.lower() + "s"))
|
||||
)
|
||||
reverse_name = child_relation_name
|
||||
relation_name = name.lower().title() + "_" + field.to.get_name()
|
||||
relationship_manager.add_relation_type(
|
||||
|
||||
@ -108,7 +108,9 @@ class Query:
|
||||
partial_match = any(
|
||||
[x.startswith(prev_part_of_related) for x in self._select_related]
|
||||
)
|
||||
already_checked = any([x.startswith(rel_part) for x in (self.auto_related + self.already_checked)])
|
||||
already_checked = any(
|
||||
[x.startswith(rel_part) for x in (self.auto_related + self.already_checked)]
|
||||
)
|
||||
return (
|
||||
(field.virtual and parent_virtual)
|
||||
or (partial_match and not already_checked)
|
||||
|
||||
@ -45,12 +45,16 @@ class RelationshipManager:
|
||||
) -> None:
|
||||
parent_id, child_id = parent._orm_id, child._orm_id
|
||||
parent_name = parent.get_name(title=True)
|
||||
child_name = child_model_name if child.get_name() != child_model_name else child.get_name()+'s'
|
||||
child_name = (
|
||||
child_model_name
|
||||
if child.get_name() != child_model_name
|
||||
else child.get_name() + "s"
|
||||
)
|
||||
if virtual:
|
||||
child_name, parent_name = parent_name, child.get_name()
|
||||
child_id, parent_id = parent_id, child_id
|
||||
child, parent = parent, proxy(child)
|
||||
child_name = child_name.lower()+'s'
|
||||
child_name = child_name.lower() + "s"
|
||||
else:
|
||||
child = proxy(child)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user