You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The 3.4.0 has introduced "Don't load relation for each column and allow dot notation in field name for index table" (#2603) which breaks previous behavior.
Steps to reproduce
Add additional relation index table columns in controller, eg
"Naslov" containing the title of the "measure" relation instance
"Naziv kategorije" containing the title of category category relation of "measure" relation instance
Actual result
Using the dot notation in filed name throws Illuminate\Database\QueryException stating SQLSTATE[42S22]: Column not found: 1054 Unknown column 'category.title' in 'field list' (Connection: mysql, SQL: select category.titlefrommeasureswheremeasures.deleted_at is null).
When I remove Relation::make()->relation('measure')->field('category.title')->title('Naziv kategorije') and use only Relation::make()->relation('measure')->field('title')->title('Naslov'), the index table renders the additional 'Naslov' column but the data is wrong: all titles of all of the relation model instances are displayed.
Possible fix
The PR #2603 changes $relation type from \Illuminate\Database\Eloquent\Collection to \App\Models\[model] as seen in src/Services/Listings/Columns/Relation.php. If I replace the new $relation = $model->getRelation($this->relation); with previous $relation = $model->{$this->relation}()->get(); I get the expected result.
@Tofandel is this an innocent regression or did I miss something?
In the case of one to one getRelation returns a model and the pluck call invokes a query instead of invoking pluck on the collection
So instead wrap it to make sure we always get a collection
Description
The 3.4.0 has introduced "Don't load relation for each column and allow dot notation in field name for index table" (#2603) which breaks previous behavior.
Steps to reproduce
Add additional relation index table columns in controller, eg
Expected result
Index table should have additional two columns:
Actual result
Using the dot notation in filed name throws
Illuminate\Database\QueryException
statingSQLSTATE[42S22]: Column not found: 1054 Unknown column 'category.title' in 'field list' (Connection: mysql, SQL: select
category.
titlefrom
measureswhere
measures.
deleted_atis null)
.When I remove
Relation::make()->relation('measure')->field('category.title')->title('Naziv kategorije')
and use onlyRelation::make()->relation('measure')->field('title')->title('Naslov')
, the index table renders the additional 'Naslov' column but the data is wrong: all titles of all of the relation model instances are displayed.Possible fix
The PR #2603 changes
$relation
type from\Illuminate\Database\Eloquent\Collection
to\App\Models\[model]
as seen in src/Services/Listings/Columns/Relation.php. If I replace the new$relation = $model->getRelation($this->relation);
with previous$relation = $model->{$this->relation}()->get();
I get the expected result.@Tofandel is this an innocent regression or did I miss something?
Versions
Twill version: 3.4.0
Laravel version: 11.28.0
PHP version: 8.3.4
Database engine: MySQL 5.7.24
The text was updated successfully, but these errors were encountered: