Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Is there a way to filter by joined tables #1904

Unanswered
kbonevska asked this question in Q&A
Discussion options

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

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /