Skip to content

Commit

Permalink
renamed table variables
Browse files Browse the repository at this point in the history
  • Loading branch information
circulon committed Oct 30, 2024
1 parent 97eaa57 commit 58edcde
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions src/masoniteorm/relationships/HasManyThrough.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ def apply_related_query(self, distant_builder, intermediary_builder, owner):
Collection: Collection of dicts which will be used for hydrating models.
"""

dist_table = distant_builder.get_table_name()
int_table = intermediary_builder.get_table_name()
distant_table = distant_builder.get_table_name()
intermediate_table = intermediary_builder.get_table_name()

return (
self.distant_builder.select(f"{dist_table}.*, {int_table}.{self.local_key}")
self.distant_builder.select(f"{distant_table}.*, {intermediate_table}.{self.local_key}")
.join(
f"{int_table}",
f"{int_table}.{self.foreign_key}",
f"{intermediate_table}",
f"{intermediate_table}.{self.foreign_key}",
"=",
f"{dist_table}.{self.other_owner_key}",
f"{distant_table}.{self.other_owner_key}",
)
.where(
f"{int_table}.{self.local_key}",
f"{intermediate_table}.{self.local_key}",
getattr(owner, self.local_owner_key),
)
.get()
Expand Down Expand Up @@ -150,31 +150,31 @@ def get_related(self, current_builder, relation, eagers=None, callback=None):
Collection the collection of dicts to hydrate the distant models with
"""

dist_table = self.distant_builder.get_table_name()
int_table = self.intermediary_builder.get_table_name()
distant_table = self.distant_builder.get_table_name()
intermediate_table = self.intermediary_builder.get_table_name()

if callback:
callback(current_builder)

(
self.distant_builder.select(
f"{dist_table}.*, {int_table}.{self.local_key}"
f"{distant_table}.*, {intermediate_table}.{self.local_key}"
).join(
f"{int_table}",
f"{int_table}.{self.foreign_key}",
f"{intermediate_table}",
f"{intermediate_table}.{self.foreign_key}",
"=",
f"{dist_table}.{self.other_owner_key}",
f"{distant_table}.{self.other_owner_key}",
)
)

if isinstance(relation, Collection):
return self.distant_builder.where_in(
f"{int_table}.{self.local_key}",
f"{intermediate_table}.{self.local_key}",
Collection(relation._get_value(self.local_owner_key)).unique(),
).get()
else:
return self.distant_builder.where(
f"{int_table}.{self.local_key}",
f"{intermediate_table}.{self.local_key}",
getattr(relation, self.local_owner_key),
).get()

Expand All @@ -189,44 +189,44 @@ def attach_related(self, current_model, related_record):
)

def query_has(self, current_builder, method="where_exists"):
dist_table = self.distant_builder.get_table_name()
int_table = self.intermediary_builder.get_table_name()
distant_table = self.distant_builder.get_table_name()
intermediate_table = self.intermediary_builder.get_table_name()

getattr(current_builder, method)(
self.distant_builder.join(
f"{int_table}",
f"{int_table}.{self.foreign_key}",
f"{intermediate_table}",
f"{intermediate_table}.{self.foreign_key}",
"=",
f"{dist_table}.{self.other_owner_key}",
f"{distant_table}.{self.other_owner_key}",
).where_column(
f"{int_table}.{self.local_key}",
f"{intermediate_table}.{self.local_key}",
f"{current_builder.get_table_name()}.{self.local_owner_key}",
)
)

return self.distant_builder

def query_where_exists(self, current_builder, callback, method="where_exists"):
dist_table = self.distant_builder.get_table_name()
int_table = self.intermediary_builder.get_table_name()
distant_table = self.distant_builder.get_table_name()
intermediate_table = self.intermediary_builder.get_table_name()

getattr(current_builder, method)(
self.distant_builder.join(
f"{int_table}",
f"{int_table}.{self.foreign_key}",
f"{intermediate_table}",
f"{intermediate_table}.{self.foreign_key}",
"=",
f"{dist_table}.{self.other_owner_key}",
f"{distant_table}.{self.other_owner_key}",
)
.where_column(
f"{int_table}.{self.local_key}",
f"{intermediate_table}.{self.local_key}",
f"{current_builder.get_table_name()}.{self.local_owner_key}",
)
.when(callback, lambda q: (callback(q)))
)

def get_with_count_query(self, current_builder, callback):
dist_table = self.distant_builder.get_table_name()
int_table = self.intermediary_builder.get_table_name()
distant_table = self.distant_builder.get_table_name()
intermediate_table = self.intermediary_builder.get_table_name()

if not current_builder._columns:
current_builder.select("*")
Expand All @@ -237,16 +237,16 @@ def get_with_count_query(self, current_builder, callback):
(
q.count("*")
.join(
f"{int_table}",
f"{int_table}.{self.foreign_key}",
f"{intermediate_table}",
f"{intermediate_table}.{self.foreign_key}",
"=",
f"{dist_table}.{self.other_owner_key}",
f"{distant_table}.{self.other_owner_key}",
)
.where_column(
f"{int_table}.{self.local_key}",
f"{intermediate_table}.{self.local_key}",
f"{current_builder.get_table_name()}.{self.local_owner_key}",
)
.table(dist_table)
.table(distant_table)
.when(
callback,
lambda q: (
Expand Down

0 comments on commit 58edcde

Please sign in to comment.