Querying ManyToOne relationship with Panache #44028
Unanswered
lordofthejars
asked this question in
Q&A
Replies: 4 comments 1 reply
-
/cc @FroMage (panache), @loicmathieu (panache) |
Beta Was this translation helpful? Give feedback.
0 replies
-
I think it's more: public static List<Subcategory> findByCategoryId(Long id) {
Category category = Category.findById(id);
return category.subcategories; // or however is named the inverse relation field
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
But with this approach, we are running two queries; in the one I did, it was only one. So, it is more performant and better for the database. |
Beta Was this translation helpful? Give feedback.
1 reply
-
you can use public static List<Subcategory> findByCategoryId(Long id) {
return Subcategory.list("category.id", id);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a one-to-many/many-to-one relationship, and I want to query all many relationships using the parent ID.
Is this correct? I know I could use a native query, but I prefer an easy way, using the Panache method.
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions