Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eaguad1337 committed Apr 6, 2024
1 parent a6a5eea commit 64585fb
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/masoniteorm/collection/Collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def first(self, callback=None):
filtered = self.filter(callback)
response = None

# print(filtered._items)
if filtered:
response = filtered[0]
return response
Expand Down
10 changes: 7 additions & 3 deletions src/masoniteorm/query/QueryBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1952,18 +1952,22 @@ def _register_relationships_to_model(
self
"""
if related_result and isinstance(hydrated_model, Collection):
map_related = related_result.group_by(related.foreign_key)
map_related = self._map_related(related_result, related)
for model in hydrated_model:
if isinstance(related_result, Collection):
print("aa", related)
related.register_related(relation_key, model, map_related)
else:
model.add_relation({relation_key: related_result or None})
else:
print("heeee", related_result)
hydrated_model.add_relation({relation_key: related_result or None})
return self

def _map_related(self, related_result, related):
if related.__class__.__name__ == 'MorphTo':
return related_result

return related_result.group_by(related.get_foreign_key())

def all(self, selects=[], query=False):
"""Returns all records from the table.
Expand Down
1 change: 0 additions & 1 deletion src/masoniteorm/relationships/BelongsTo.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def get_related(self, query, relation, eagers=(), callback=None):
).first()

def register_related(self, key, model, collection):
print('ooooo', collection._items, "tttt", model.serialize(), model, getattr(model, self.local_key))
related = collection.get(getattr(model, self.local_key), None)

model.add_relation({key: related[0] if related else None})
3 changes: 1 addition & 2 deletions src/masoniteorm/relationships/HasMany.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def set_keys(self, owner, attribute):
return self

def register_related(self, key, model, collection):
print("zzzzzz", getattr(model, self.local_key), collection._items)
model.add_relation(
{key: collection.get(getattr(model, self.local_key))}
{key: collection.get(getattr(model, self.local_key)) or Collection()}
)
2 changes: 1 addition & 1 deletion src/masoniteorm/relationships/MorphTo.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __get__(self, instance, owner):

def __getattr__(self, attribute):
relationship = self.fn(self)()
return getattr(relationship.builder, attribute)
return getattr(relationship._related_builder, attribute)

def apply_query(self, builder, instance):
"""Apply the query and return a dictionary to be hydrated
Expand Down
3 changes: 0 additions & 3 deletions tests/sqlite/relationships/test_sqlite_relationships.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import os
import unittest

from src.masoniteorm.models import Model
from src.masoniteorm.relationships import belongs_to, has_many, has_one, belongs_to_many
from tests.integrations.config.database import DB


class Profile(Model):
__table__ = "profiles"
__connection__ = "dev"
Expand Down

0 comments on commit 64585fb

Please sign in to comment.