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

Is there a way to filter by joined tables #1905

Open
kbonevska opened this issue Aug 4, 2021 Discussed in #1904 · 0 comments
Open

Is there a way to filter by joined tables #1905

kbonevska opened this issue Aug 4, 2021 Discussed in #1904 · 0 comments

Comments

@kbonevska
Copy link

Discussed in #1904

Originally posted by kbonevska August 4, 2021
Hey, there guys, I've been using your project for some time and it seems amazing by now. Thank you for your effort.
I was wondering if I am missing something and there is actually a way to filter by joined tables. So far following the examples, it doesn`t seem possible by using Relation().

type Product struct {
	ID               int64
	Name             string
        Tags             []GrTag             `pg:",many2many:product_tags"`
}

In the following model, while selecting products with their tags, how can I sort by tag names, I tried something like

DB.Model(&p).Column("product.*").
Relation("Tags", func ( q *pg.Query)(*pg.Query, error){
	return q.Where("tag.name = 'tag 1'"), nil
})

but this will filter out just tags by the name, not products by the tag name

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