We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Imagine you have list of products with many to many relation with categories.
products
categories
Below code works fine
products = Product.with_("categories").get()
[ { "id": 1, "name": "Product 1", "categories": [ { "id": 1, "name": "Category 1", "status": "published" }, { "id": 2, "name": "Category 2", "status": "draft" } ] } ]
Filtering with_ lambda (Doesn't work)
products = Product.with_("categories", lambda query: ( query.where("status", "published") )).get()
Expected Result
[ { "id": 1, "name": "Product 1", "categories": [ { "id": 1, "name": "Category 1", "status": "published" }, ] } ]
Actual Result
The text was updated successfully, but these errors were encountered:
belongs_to_many
Sorry, something went wrong.
Model class looks like this:
"""CommerceProduct Model.""" class Product(Model): """Product Model.""" __primary_key__ = "id" __fillable__ = [ #... ] @belongs_to_many( local_foreign_key="product_id", other_foreign_key="category_id", table="category_product", ) def categories(self): """Returns all categories for this product.""" from ..models.Category import Category return Category
I could only get this to work with the belongs to if you did this:
products = Product.with_("categories", lambda query: ( query.where("categories.status", "published") )).get()
Successfully merging a pull request may close this issue.
Imagine you have list of
products
with many to many relation withcategories
.Below code works fine
Filtering with_ lambda (Doesn't work)
Expected Result
Actual Result
The text was updated successfully, but these errors were encountered: