根据蛋糕3.x

时间:2015-10-10 23:01:19

标签: php cakephp cakephp-3.0 cakephp-3.1

我有三张桌子:

1个lab_categories(列包括idcategory

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个实验室(列包括idname

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个laboratories_lab_categories(列包括idlaboratory_idlab_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,类别 来自lab_categories 加入laboratories_lab_categories 其中laboratories_lab_categories.laboratory_id = $ id AND laboratories_lab_categories.lab_category_id = lab_categories.id

我正在使用cakephp 3.1并且桌子被烘焙了。我搜索了相关问题,但非适用于我。

0 个答案:

没有答案