【发布时间】:2017-01-23 15:18:28
【问题描述】:
后端列表:按 HasMany 关系中的字段排序和过滤
我有两个相关的模特与戏剧作品和他们的表演:
class Play extends Model
{
...
public $table = 'johar_theater_plays';
public $hasMany = ['playtimes' => 'johar\Theater\Models\PlayTime'];
}
class PlayTime extends Model
{
...
public $table = 'johar_theater_plays_times';
public $belongsTo = ['play' => ['johar\Theater\Models\Play']];
}
我将通过 play 表单中的关系管理器管理游戏时间。
要在play-list 中显示playtimes,我发现有两种可能性:
playtimes:
relation: playtimes
select: time
type: myRenderFunction
playtimes:
type: myRenderFunction
sortable: true
第一种类型使用$value 中的集合调用我的函数,第二种使用JSON 字符串。
在第二种类型中,我可以按播放时间排序 - 它可能只是对 JSON 字符串进行排序,但这没关系。
但是我发现没有办法创建过滤器范围来过滤掉今天之后没有表现的所有播放。 我试过了
scope:
condition: playtimes.time > now()
恕我直言,它的所有可能变体。以及创建一个范围函数,我在其中修改了不同的 where 子句。 问题始终是 SQL 将 JOIN 放入 group_concat:
"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'time' in 'where clause'
(SQL: select `johar_theater_plays`.*,
(select group_concat(time separator ', ')
from `johar_theater_plays_times`
where `johar_theater_plays_times`.`play_id` = `johar_theater_plays`.`id`)
as `playtimes`
from `johar_theater_plays`
where `time` > 2016-12-12 00:00:00
order by `playtimes` desc)" on line 662 of E:\..\Illuminate\Database\Connection.php
所以简短的问题是:
当Play HasMany Playtimes
【问题讨论】:
标签: octobercms octobercms-backend