I have an index method:
public function index()
{
$this->set('contracts',
$this->paginate(
$this->Contracts
->find()
->contain('Currencies'])
->where(['Contracts.created_by_id' => $this->Auth->user('id')])
->order(['Contracts.created' => "desc"])
)
);
$this->set('_serialize', ['contracts']);
}
The problem is that it returns only records that has Currency (in my DB table currency_id).The ones with currency_id = null
. So I simply want to get all the records no matter if they have the currency_id is null or not null, but at the same time keep having Currency entity returned in my results
If you have had baked the model then you would have this problem. Because by baking the model default model association would be set to 'INNER JOIN'.
If you look at you 'ContactsTable' in src/model/ContactsTable make sure you are 'LEFT JOIN' ing the 'User' table or you can completely remove the 'joinType' because in default cakephp sets the Contain or join to 'LEFT JOIN'
class ContactsTable extends Table
{
public function initialize(array $config)
{
$this->belongsTo('Currencies', [
'foreignKey' => 'created_by_id',
'joinType' => 'LEFT'
]);
}
}