F
Filamentβ€’11mo ago
Prodex

QueryBuilder Filter returns nothing

Hi, I have this simple RealtionshipContraint in my filter querybuilder. The items of the relation is displayed correctly in the select, but if one item is select with "is" operator, it doesn't return anything. To double check: It disabled / removed all other filters to avoid possible conflicts. But it still doesn't work:
QueryBuilder::make()
->constraints([
QueryBuilder\Constraints\TextConstraint::make('customer.name'),
QueryBuilder\Constraints\RelationshipConstraint::make('article')
->emptyable()
->selectable(QueryBuilder\Constraints\RelationshipConstraint\Operators\IsRelatedToOperator::make()
->titleAttribute('title'))]),
QueryBuilder::make()
->constraints([
QueryBuilder\Constraints\TextConstraint::make('customer.name'),
QueryBuilder\Constraints\RelationshipConstraint::make('article')
->emptyable()
->selectable(QueryBuilder\Constraints\RelationshipConstraint\Operators\IsRelatedToOperator::make()
->titleAttribute('title'))]),
"is empty" and "is not empty" works. The relationship itself works too, when it is used in other filters or fields. Can anyone help?
2 Replies
Prodex
ProdexOPβ€’11mo ago
After some debugging, I figured out, that the query is using "id" to resolve the column of the relation, but my relation is actually using a different name for that:
public function article(): BelongsTo
{
return $this->belongsTo(Article::class, 'billomat_article_id', 'billomat_id');
}
public function article(): BelongsTo
{
return $this->belongsTo(Article::class, 'billomat_article_id', 'billomat_id');
}
How can I modify the query, so that it uses the correct column name? It needs to be "billomat_id" in order to work. anyone? πŸ™
Xiquita
Xiquitaβ€’11mo ago
Based on your description, it seems like there might be an issue with the is operator in the RelationshipConstraint. One possible reason could be that the titleAttribute is not configured correctly. Make sure that you are specifying the correct attribute that represents the title in the article relationship. Additionally, you can try using the isExactly operator instead of is to see if it returns the expected results. For example: QueryBuilder::make() ->constraints([ QueryBuilder\Constraints\TextConstraint::make('customer.name'), QueryBuilder\Constraints\RelationshipConstraint::make('article') ->emptyable() ->selectable(QueryBuilder\Constraints\RelationshipConstraint\Operators\IsRelatedToOperator::make() ->titleAttribute('title') ->isExactly())]), If the issue persists, it might be helpful to provide more information about the data structure and any error messages you are receiving.
Want results from more Discord servers?
Add your server