私は以下のようなテーブルを持っています。今は年ごとに行を取得することはできません。CakePHP 3 - 日付(年)でテーブルを含む行を選択してください
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Matches.date' in 'where clause'
私の "マッチ" テーブル
id | goalsfor | goalsagainst | date
1 | 5 | 4 | 2017-07-05 15:57:36
2 | 9 | 5 | 2017-07-05 17:06:31
3 | 7 | 8 | 2015-07-05 15:57:36
4 | 0 | 2 | 2014-07-05 15:57:36
6 | 5 | 4 | 2014-07-05 15:57:36
7 | 7 | 9 | 2014-07-05 15:57:36
マイクエリ:
$playedMatches = $this->Players
->find()
->contain([
'MatchePlayers' => [
'Matches'
]
]);
$playedMatches->where(['YEAR(Matches.date) =' => "2017"]);
マイ団体:私はこれをしようとすると、しかし、私は次のエラーを取得します
含まれているため、あなたの構文が間違っているclass PlayersTable extends Table {
public function initialize(array $config) {
parent::initialize($config);
$this->setTable('players');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->hasMany('MatchePlayers', [
'className' => 'MatchPlayers',
'foreignKey' => 'player_id',
'propertyName' => 'matches',
'dependent' => true
]);
}
}
class MatchPlayersTable extends Table {
public function initialize(array $config) {
parent::initialize($config);
$this->setTable('matches_players');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->belongsTo('Players', [
'className' => 'Players',
'foreignKey' => 'player_id',
'propertyName' => 'player'
]);
$this->belongsTo('Matches', [
'className' => 'Matches',
'foreignKey' => 'match_id',
'propertyName' => 'match'
]);
}
}
これは素晴らしい作品です! tx – CodeWhisperer