Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when working with multiple models #86

Open
macthefloof opened this issue Oct 3, 2022 · 1 comment
Open

Error when working with multiple models #86

macthefloof opened this issue Oct 3, 2022 · 1 comment

Comments

@macthefloof
Copy link

When working with 2 different models, it seems like mongox is ignoring the collection name and inserting into the first one's collection.

Currently, I have 2 models defined in 2 different files:

class UserAction(mongox.Model, db=db, collection="user_actions"):
    server_id: int
    name: str
    aliases: list[str]
    emoji: str
    self_text: str
    receivers_text: list[str]
class ServerSetting(mongox.Model, db=db, collection="server_settings"):
    server_id: int
    ignored_channels: list[int]

Firstly, I insert into server_settings, but when I try to insert into user_actions, the object gets created inside the server_settings collection instead.

@macthefloof
Copy link
Author

I have made a simple script to run that displays the bug in full.

import asyncio

import mongox

client = mongox.Client("mongodb://localhost:27017")
db = client.get_database("test_db")


class Movie(mongox.Model, db=db, collection="movies"):
    name: str
    year: int
    genres: list[str]


class Book(mongox.Model, db=db, collection="books"):
    title: str
    author: str
    year: int


async def test() -> None:
    forrest_gump = await Movie(name="Forrest Gump", year=1994, genres=["Comedy", "Tragedy"]).insert()
    nineteen84 = await Book(title="1984", author="George Orwell", year=1949).insert()
    print(forrest_gump.name)
    print(nineteen84.title)


if __name__ == "__main__":
    asyncio.run(test())

In this case, we get the following result when viewed in Compass:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant