SHARE
TWEET

Untitled

a guest Dec 3rd, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from this error I don't understand why I read in the documentation but I couldn't solve
  2.  
  3. The Dogs association is not defined on DogsCats.
  4.  
  5.  
  6. Model/Table/Dogs
  7.  
  8. <?php
  9.  
  10. use App\Model\Entity\Dog;
  11. use Cake\ORM\Table;
  12. use Cake\ORM\Query;
  13. use Cake\ORM\RulesChecker;
  14. use Cake\ORM\Validation\Validator;
  15.  
  16.  
  17. class DogsTable extends Table
  18. {
  19.     public function initialize(array $config)
  20.     {
  21.         $this->addBehavior('Timestamp');
  22.  
  23.  
  24.  
  25.         $this->hasMany('DogsCats',[
  26.             'foreignKey'=>'dog_id'
  27.         ]);
  28.     }
  29.  
  30.  
  31. }
  32.  
  33. Model/Table/Cats
  34.  
  35. <?php
  36.  
  37. use App\Model\Entity\Cat;
  38. use Cake\ORM\Table;
  39. use Cake\ORM\Query;
  40. use Cake\ORM\RulesChecker;
  41. use Cake\ORM\Validation\Validator;
  42.  
  43.  
  44.  
  45. class CatsTable extends Table
  46. {
  47.     public function initialize(array $config)
  48.     {
  49.  
  50.         $this->addBehavior('Timestamp');
  51.  
  52.  
  53.         $this->hasMany('DogsCats',[
  54.             'foreignKey'=>'cat_id'
  55.         ]);
  56.     }
  57.  
  58.  
  59. }
  60.  
  61. Model/Table/DogsCats
  62.  
  63. <?php
  64.  
  65. use App\Model\Entity\DogCat;
  66. use Cake\ORM\Table;
  67. use Cake\ORM\Query;
  68. use Cake\ORM\RulesChecker;
  69. use Cake\ORM\Validation\Validator;
  70.  
  71.  
  72.  
  73. class DogsCatsTable extends Table
  74. {
  75.     public function initialize(array $config)
  76.     {
  77.         $this->addBehavior('Timestamp');
  78.  
  79.  
  80.         $this->belongsTo('Dogs', [
  81.             'foreignKey' => 'id',
  82.             'joinType'=>'INNER',
  83.         ]);
  84.  
  85.         $this->belongsTo('Cats', [
  86.             'foreignKey' => 'id',
  87.             'joinType'=>'INNER',
  88.         ]);
  89.     }
  90.  
  91.  
  92. }
  93.  
  94. Controller/DogsCats
  95.  
  96. <?php
  97.  
  98. namespace App\Controller;
  99.  
  100.  
  101. class DogsCatsController extends AppController
  102. {
  103.     public function initialize()
  104.     {
  105.         parent::initialize();
  106.  
  107.         $this->loadComponent('Paginator');
  108.         $this->loadComponent('Flash'); // Include the FlashComponent
  109.     }
  110.  
  111.     public function index()
  112.     {
  113.  
  114.         $result = $this->DogsCats->find('all')->contain(['Dogs','Cats']);
  115.         $this->set('farms',$result);
  116.    
  117.  
  118.     }
  119.  
  120.    
  121.  
  122.  
  123.  
  124. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top