Chinmay235
Chinmay235

Reputation: 3414

MySQL Query - How to check second table record exist or not?

I am using cakephp v.3.2. Now I am facing some problem my query. Please check below my json record -

{
    "id": 22,
    "title": "",
    "description": "vfdvfdvffd",
    "type": 0,
    "allow_comment": 0,
    "owner_id": 35,
    "created": "2016-04-11T12:02:29+0000",
    "status": 1,
    "post_images": []
 },

I have two tables one is posts and another is post_images I am using hasmany. But I want to show all the records which is no post_images.

I am trying following code but not working. Please see my code -

$get_post_list_for_photo_tab = $this->Posts->find('all')
           ->where([
                  'Posts.owner_id' =>$query_for_school_admin['id'],
                  'post_images !='=>''])
           ->contain(['PostImages'])
           ->order(['created' => 'DESC'])->toArray();

Please help me.

Upvotes: 0

Views: 57

Answers (1)

floriank
floriank

Reputation: 25698

Two possibile solutions:

Upvotes: 1

Related Questions