0

我有三张桌子:

1 lab_categories(列包括id, category

class LabCategoriesTable extends Table
{
    public function initialize(array $config)
    {
        parent::initialize($config);

        $this->table('lab_categories');
        $this->displayField('id');
        $this->primaryKey('id');

        $this->hasMany('LabTests', [
            'foreignKey' => 'lab_category_id'
        ]);
        $this->belongsToMany('Laboratories', [
            'foreignKey' => 'lab_category_id',
            'targetForeignKey' => 'laboratory_id',
            'joinTable' => 'laboratories_lab_categories'
        ]);
    }}

2 个实验室(列包括id, name

class LaboratoriesTable extends Table
{

    public function initialize(array $config)
    {
        parent::initialize($config);

        $this->table('laboratories');
        $this->displayField('name');
        $this->primaryKey('id');

        $this->hasMany('LabRefValues', [
            'foreignKey' => 'laboratory_id'
        ]);
        $this->belongsToMany('LabCategories', [
            'foreignKey' => 'laboratory_id',
            'targetForeignKey' => 'lab_category_id',
            'joinTable' => 'laboratories_lab_categories'
        ]);
    }}

3 个实验室_实验室_类别(列包括id, laboratory_id, lab_category_id

class LaboratoriesLabCategoriesTable extends Table
{
    public function initialize(array $config)
    {
        $this->table('laboratories_lab_categories');
        $this->displayField('id');
        $this->primaryKey('id');
        $this->belongsTo('Laboratories', [
            'foreignKey' => 'laboratory_id',
            'joinType' => 'INNER'
        ]);
        $this->belongsTo('LabCategories', [
            'foreignKey' => 'lab_category_id',
            'joinType' => 'INNER'
        ]);
    }}

我希望能够选择lab_categories.name与指定的关联,laboratory.id以便能够将其添加到我创建的 ajax 调用中。我想生成类似于此查询将生成的结果;选择 lab_categories.id,category From lab_categories 加入laboratory_lab_categories wherelaboratory_lab_categories.laboratory_id=$id AND Laboratory_lab_categories.lab_category_id=lab_categories.id

我正在使用cakephp 3.1,桌子已经烤好了。我已经搜索了相关问题,但不适用于我。

4

0 回答 0