Skip to content

conditions on belongsTo #17017

Closed
Closed
@tgoeminne

Description

@tgoeminne

Description

The conditions on belongsTo relation still can not make conditions based on its own data.

in ArticlesTable

$this->belongsTo('Users', [
            'className' => 'Users',
            'foreignKey' => 'writer_id',
            'joinType' => 'INNER',
            'conditions' => ['Articles.type_id' => '1']
]);
$this->belongsTo('Admins', [
    'className' => 'Admins',
    'foreignKey' => 'writer_id',
    'joinType' => 'INNER',
    'conditions' => ['Articles.type_id' => '2'],
]);

SQLSTATE[42S22]: Column not found: 1054 Unknown column Articles.type_id

How to use the conditions in belongsTo on its own table?

CakePHP Version

4.4

PHP Version

8

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions