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

Add add_select query #350

Closed
josephmancuso opened this issue Jan 30, 2021 · 0 comments · Fixed by #351
Closed

Add add_select query #350

josephmancuso opened this issue Jan 30, 2021 · 0 comments · Fixed by #351

Comments

@josephmancuso
Copy link
Member

josephmancuso commented Jan 30, 2021

A really cool feature of other orms is the ability to add a select query in place of the column name so you can select based on a relationship or based on another query.

An example of this type of query is:

select code, (select count(*) from order_skus where order_skus.order_id = orders.order_id) as sku_count from orders

This would select the order code plus the number of skus the order has and return the code and sku_count.

In the ORM this should look something like:

User.where('active', 1).add_select({'sku_count', lambda query: (
     query.where_column('order_skus.order_id', "orders.order_id").count('*')
)})
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

Successfully merging a pull request may close this issue.

1 participant