我尝试排序" hasMany"准
这是我的代码:
Advisor Modal
$this->hasMany('AdvisorNotes', [
'foreignKey' => 'id',
'sort' => [
'created' => 'DESC',
],
'joinType' => 'LEFT',
]);
顾问控制器
public function index() {
$this->paginate = [
'contain' => [
'Branch' => [ 'BranchCity', 'Bank' ],
'AdvisorLevel',
'AdvisorRelation',
'UsersAgent',
'AdvisorNotes'
],
'sortWhitelist' => [
'BranchCity.city_name',
'Branch.name',
'Advisor.name',
'AdvisorRelation.relation',
'AdvisorLevel.level',
'Advisor.telephone',
'UsersAgent.name',
'AdvisorNotes.created',
'Bank.name',
]
];
$advisors = $this->paginate( $this->Advisor );
AdvisorNotes表 id | advisor_id | agent_id | type_id |注意|创建
顾问表 id |名字|图片| date_of_birth | important_date | branch_id |电话|传真|手机|电子邮件|描述| level_id | relation_id | agent_id | agent_admin_id |创建
我尝试在Advisor索引中创建显示最后一个AdvisorNote并且能够对其进行排序的字段。
您可以在表格中看到AdvisorNotes为advisor_id,但Advisor没有任何AdvisorNotes的ID。
感谢。