Issue
I am trying to give a condition in cakephp
3 get method, where data will fetch by foreign id not primary key. Here I have tried below code:
$eventPasswordAll = $this->EventPasswordAll->get($id, [
'conditions' => ['event_id'=>$id],
'contain' => ['Events']
]);
But it showing me data according to id(primary key)
, not by event_id
. How I add this condition in get methods like where event_id=my get id
?
Solution
Don't use get
, use find
. According to CakePHP 3.0 Table API, the get
method:
Returns a single record after finding it by its primary key, if no record is found this method throws an exception.
You need to use find
:
$eventPasswordAll = $this->EventPasswordAll->find('all', [ // or 'first'
'conditions' => ['event_id' => $id],
'contain' => ['Events']
]);
// or
$eventPasswordAll = $this->EventPasswordAll->find()
->where(['event_id' => $id])
->contain(['Events']);
Answered By - Holt
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.