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

Wednesday, January 5, 2022

[FIXED] Get related data in contain request

 January 05, 2022     cakephp, cakephp-3.0     No comments   

Issue

Consider these (CakePHP3) models and their relations:

Menus

name | user_id

Menutimetables

herd_id | menu_id | start | end

Menus hasMany Menutimetables

Menutimetables belongsTo Menus

Menutimetables belongsTo Herds

Herds hasMany Menutimetables

In my controller I'm getting all data with

$herd = $this->Herds->get($id, [
    'contain' => [
        'Menutimetables' => ['sort' => ['start'=>'asc']]
    ]
]);

Which results in getting the menu_id.

menu_id   start   end
8         1       5
9         6       9
6         10      15

Where in fact I want to see the Menus.name.

How can I get that?


Solution

Try:

$herd = $this->Herds->get($id, [
    'contain' => [
        'Menutimetables.Menus'
        'Menutimetables' => ['sort' => ['start'=>'asc']]
    ]
]);


Answered By - Salines
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

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