PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 19, 2022

[FIXED] CakePHP retrieving when related model NULL

 March 19, 2022     cakephp-3.0, orm     No comments   

Issue

I have a null-able relation model, and I am using this standard code to retrieve my records:

$this->paginate = [
    'contain' => ['Clients']
];
$coupons = $this->paginate($this->Coupons);

I am getting just the records that have client associated. what is the best practice to make the contain work like OR, and not AND

EDIT: the relationship is seted as the following:

$this->belongsTo('Clients', [
    'foreignKey' => 'client_id',
    'joinType' => 'INNER'
]);

Solution

I have solved it by setting the joinType to LEFT:

$this->belongsTo('Clients', [
    'foreignKey' => 'client_id',
    'joinType' => 'LEFT'
]);


Answered By - Eymen Elkum
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing