使用链接的 table 值扩展模型。在cakephp3中

Extend model with linked table values. In cakephp3

开始学习cakephp3。 有两张桌子

Task
-id
-task_type

Task_content
-id
-task_id
-some_key
-sove_val

结果我想得到一些对象,它看起来像:

{
id: Task.id,
type: Task.type,
title: Task_content.some_val (where some_key == 'title')
content: Task_content.some_val (where some_key == 'conent')
}

获取此对象的最佳方法是什么,只需通过 "get" 获取任务?

您需要创建一个行为来处理这个问题。您可以从 Translates Behavior 中获得灵感,它做的事情非常相似:

https://github.com/cakephp/cakephp/blob/master/src/ORM/Behavior/TranslateBehavior.php