0

I am new to cakephp 3.2. i want to get only first row (or only one row instead of all row) of association table in cakephp . I have used below query to get it ,but not getting the exact result what i need.(its only working for first row ,after it not working.)

 $fetchCampaignFirst = $this->Campaigns->find()->contain(['CampaignVideos' => ['queryBuilder' => function ($q) {
                            return $q->limit(1);
                        }]]));

Its giving out put like.

[
    {
        "id": 1,
        "user_id": 95,
        "unique_id": "e47d2a7d13151c96944e235c6f5be5d0",

        "campaign_videos": [
            {
                "id": 1,
                "campaign_id": 1,

            }
        ]
    },
    {
        "id": 2,

        "campaign_videos": []
    },
    {
        "id": 3,

        "campaign_videos": []
    },

Here campaign_videos is empty for id 2 and 3 while its coming only for id 1(id 1 has 3 records ,from which i want only 1,so i have tried above code ,its not working for id 2 and 3 at all). Please suggest me. Any suggestion will highly appreciate.

sradha
  • 2,216
  • 1
  • 28
  • 48

0 Answers0