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

Limit does not work properly with m2m #496

Open
imraan-go opened this issue Mar 23, 2022 · 2 comments
Open

Limit does not work properly with m2m #496

imraan-go opened this issue Mar 23, 2022 · 2 comments
Labels
enhancement New feature or request stale

Comments

@imraan-go
Copy link

imraan-go commented Mar 23, 2022

So here is the scenario, I want to select 2 items from each order on the following example: https://bun.uptrace.dev/guide/relations.html#many-to-many-relation

orders := []Order{}
db.NewSelect().Model(&orders).Relation("Items", func(q *bun.SelectQuery) *bun.SelectQuery {
		return q.Limit(2)
	}).Scan(ctx)

The following query only selects first 2 items instead of selecting 2 items per product.

@vmihailenco
Copy link
Member

This is a limitation of the current m2m query generator. Perhaps we should check if limit != 0 and issue a separate query for each order.

@vmihailenco vmihailenco added the enhancement New feature or request label Mar 23, 2022
Copy link

github-actions bot commented Nov 7, 2024

This issue has been automatically marked as stale because it has not had activity in the last 30 days. If there is no update within the next 7 days, this issue will be closed.

@github-actions github-actions bot added the stale label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request stale
Projects
None yet
Development

No branches or pull requests

2 participants