首页 > 解决方案 > 在 Cakephp 4 上有很多

问题描述

我想用 1 笔交易很多产品进行交易。但我只有在产品上输入的最后一个索引有问题。有解决办法吗?这是我的控制器

[型号表][2]

标签: cakephp-3.0cakephp-4.x

解决方案


只需确保您在选择查询中使用数组即可。获取所有记录。例如,

$posts = $this->Employees->find("all")
        ->contain(["employeePosts" => function($q){
        return $q->select(["id", "employee_id", "post_title"]);
         }])
        ->toList();
 echo print_r("posts"); 

这里employee_id 是外键。并且employeePosts 是我在HasMany() 的EmployeesTable 中创建的一个键

$this->hasMany("employeeposts")->setClassName("Posts")

推荐阅读