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

Implement better JOIN semantics #113

Merged
merged 1 commit into from Nov 23, 2017

Conversation

Projects
None yet
2 participants
@brncsk
Copy link
Contributor

brncsk commented Nov 23, 2017

This PR does two things:

  1. It exposes join() from the underlying sqlalchemy.schema.Table directly onto gino.declarative.ModelType. insert() was already exposed, see:
    https://github.com/fantix/gino/blob/master/gino/declarative.py#L32.

  2. It registers gino.declarative.ModelType as an "inspectable" type to SQLAlchemy, by dispatching the inspection to, again, the model's underlying table.

These changes allow for friendlier semantics when writing JOIN queries (see #112):

Model1.join(Model2)

instead of

Model1.__table__.join(Model2.__table__)

also

import join from sqlalchemy
join(Model1, Model2)

instead of

import join from sqlalchemy
join(Model1.__table__, Model2.__table__)

@brncsk brncsk referenced this pull request Nov 23, 2017

Closed

JOIN queries do not work #112

@fantix

This comment has been minimized.

Copy link
Owner

fantix commented Nov 23, 2017

Impressive! Thx for the PR

@brncsk

This comment has been minimized.

Copy link
Contributor Author

brncsk commented Nov 23, 2017

To provide a bit more context: registering ModelType as inspectable allows sqlalchemy.sql.selectable._interpret_as_from() to recognize Gino models as Selectable.

_interpret_as_from() is called when constructing JOINs and currently throws an sqlalchemy.exc.ArgumentError: FROM expression expected.

@fantix fantix merged commit 1b84fe9 into fantix:master Nov 23, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@fantix

This comment has been minimized.

Copy link
Owner

fantix commented Nov 23, 2017

Also reviewed relevant SQLAlchemy code 😃

@fantix fantix referenced this pull request Mar 12, 2018

Closed

JOIN does not work #155

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment