Skip to content

Many to one relationship not recognised as list #152

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

Open
maitham opened this issue Apr 28, 2020 · 3 comments
Open

Many to one relationship not recognised as list #152

maitham opened this issue Apr 28, 2020 · 3 comments

Comments

@maitham
Copy link

maitham commented Apr 28, 2020

The accounts object is not recognised as a list, when it is a many to one relationship. Am I doing something wrong here?


if TYPE_CHECKING:
    from .account import Account  # noqa: F401

class User(Base):
    id = Column(Integer, primary_key=True, index=True)
    accounts = relationship("Account", cascade="all,delete", backref="user")
@3rdcycle
Copy link

Having run into this issue myself and looking at the code in sqlmypy.py it seems that you need to add an explicit uselist=True for it to work, even though this is the default value.

@ExplodingCabbage
Copy link

ExplodingCabbage commented Jun 22, 2020

... and even then sqlmypy seems to only treat the relationship as an Iterable rather than a List, meaning it wrongly thinks you can't do things like do an index lookup on the relationship or append to it.

@lukaszdudek-codibly
Copy link

It seems that the only change to be made here is here:

new_arg = ctx.api.named_generic_type('typing.Iterable', [new_arg])

and some tests as well.

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

4 participants