defaultGroup set to attribute from parent relationship fractures group
Hi all, I have a Category model with a
parent_id
that can reference another category. This is only used for categories with a single level of subcategories below them.
If I set defaultGroup('parent_id')
it works as I'd expect, with the top level categories ungrouped at the top, followed by a group for each.
However if I set defaultGroup('parent.title')
the groups repeat themselves with only a couple of items under each level. There's no clear pattern to why they're grouped up separately, and in some cases it skips over a group until the next "cycle"
Expected:
Actual:
7 Replies
This behaviour is consistent with or without any sorting set, and whether or not the table includes a column for the
parent.title
.
Using parent_id
and rewriting the title using the record works as expected, but it lazy loads the parent relationship.
Works as expected:
->defaultGroup('parent_id')
Fractures groups:
->defaultGroup('parent.title')
Disabling pagination doesn't change the behaviour and the queries being run make sense:
Setting the key to the ID manually also doesn't change the behaviour:
are your relations set up correctly?
Yup,
BelongsTo
on parent()
cant seem to replicate the issue you are facing so can't be of much help
The groups shown are correct, and it works if I use
getTitleFromRecordUsing()
, but for some reason the default Filament behaviour is splitting them up , mostly, but not perfectly at letter boundaries.
I assume it's related to it being grouped by a self-referential relationship.
Possibly a collision on the order clause.It was as stupid as I thought. By default the query gets sorted by the grouping column, which is normalised using
str($name)->afterLast('.')
.
But as this is a recursive relationship and we're sorting on the title, it ends up just sorting it by the title of the child and then applying the groups. Adding an orderQueryUsing
call that sorts by the parent_id
solves it, though it does mean the groups themselves won't be alphabetically sorted.