Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ def setUpClass(cls) -> None:
foreign_key_target="id",
type=FieldType.MANY_TO_ONE,
),
"editor_id": Column(column_type=PrimitiveType.NUMBER, type=FieldType.COLUMN),
"editor": ManyToOne(
foreign_collection="Person",
foreign_key="editor_id",
foreign_key_target="id",
type=FieldType.MANY_TO_ONE,
),
"title": Column(
column_type=PrimitiveType.STRING,
type=FieldType.COLUMN,
Expand Down Expand Up @@ -126,6 +133,30 @@ def test_should_join_when_projection_ask_for_multiple_fields_in_foreign_collecti
result,
)

def test_should_work_with_multiple_relations(self):
with patch.object(
self.collection_book,
"list",
new_callable=AsyncMock,
return_value=[{"id": 1, "author_id": 2, "editor_id": 3}, {"id": 2, "author_id": 5, "editor_id": 6}],
) as mock_list:
result = self.loop.run_until_complete(
self.decorated_book_collection.list(
self.mocked_caller,
PaginatedFilter({}),
Projection("id", "author:id", "editor:id"),
)
)
mock_list.assert_awaited_once_with(
self.mocked_caller, PaginatedFilter({}), Projection("id", "author_id", "editor_id")
)

# should contain author object, without author_id FK
self.assertEqual(
[{"id": 1, "author": {"id": 2}, "editor": {"id": 3}}, {"id": 2, "author": {"id": 5}, "editor": {"id": 6}}],
result,
)

def test_should_not_join_when_condition_tree_is_on_foreign_key_target(self):
with patch.object(
self.collection_book,
Expand Down
Loading