Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from this error I don't understand why I read in the documentation but I couldn't solve
- The Dogs association is not defined on DogsCats.
- Model/Table/Dogs
- <?php
- use App\Model\Entity\Dog;
- use Cake\ORM\Table;
- use Cake\ORM\Query;
- use Cake\ORM\RulesChecker;
- use Cake\ORM\Validation\Validator;
- class DogsTable extends Table
- {
- public function initialize(array $config)
- {
- $this->addBehavior('Timestamp');
- $this->hasMany('DogsCats',[
- 'foreignKey'=>'dog_id'
- ]);
- }
- }
- Model/Table/Cats
- <?php
- use App\Model\Entity\Cat;
- use Cake\ORM\Table;
- use Cake\ORM\Query;
- use Cake\ORM\RulesChecker;
- use Cake\ORM\Validation\Validator;
- class CatsTable extends Table
- {
- public function initialize(array $config)
- {
- $this->addBehavior('Timestamp');
- $this->hasMany('DogsCats',[
- 'foreignKey'=>'cat_id'
- ]);
- }
- }
- Model/Table/DogsCats
- <?php
- use App\Model\Entity\DogCat;
- use Cake\ORM\Table;
- use Cake\ORM\Query;
- use Cake\ORM\RulesChecker;
- use Cake\ORM\Validation\Validator;
- class DogsCatsTable extends Table
- {
- public function initialize(array $config)
- {
- $this->addBehavior('Timestamp');
- $this->belongsTo('Dogs', [
- 'foreignKey' => 'id',
- 'joinType'=>'INNER',
- ]);
- $this->belongsTo('Cats', [
- 'foreignKey' => 'id',
- 'joinType'=>'INNER',
- ]);
- }
- }
- Controller/DogsCats
- <?php
- namespace App\Controller;
- class DogsCatsController extends AppController
- {
- public function initialize()
- {
- parent::initialize();
- $this->loadComponent('Paginator');
- $this->loadComponent('Flash'); // Include the FlashComponent
- }
- public function index()
- {
- $result = $this->DogsCats->find('all')->contain(['Dogs','Cats']);
- $this->set('farms',$result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement