Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. The join table : TestsRegistrations
  2. Tests table
  3. Registrations table
  4. People table
  5.  
  6.  
  7.  
  8.  
  9. // TestsRegistrations table
  10. $this->belongsTo('Tests'
  11. , [
  12. 'foreignKey' => 'test_id',
  13. 'joinType' => 'INNER'
  14. ]
  15. );
  16.  
  17. $this->hasMany('Registrations', [
  18. 'foreignKey' => 'registration_id',
  19. 'joinType' => 'INNER'
  20. ]);
  21.  
  22. ///Tests table
  23. $this->belongsToMany('Registrations', [
  24. 'className'=>'Registrations',
  25. 'foreignKey' => 'test_id',
  26. 'targetForeignKey' => 'registration_id',
  27. 'joinTable' => 'tests_registrations',
  28. //'through'=>'tests_registrations'
  29. ]);
  30.  
  31. ///Registrations table
  32. $this->belongsToMany('Tests', [
  33. 'className'=>'Tests',
  34. 'foreignKey' => 'registration_id',
  35. 'targetForeignKey' => 'test_id',
  36. 'joinTable' => 'tests_registrations',
  37. //'through'=>'tests_registrations'
  38. ]);
  39.  
  40. $this->belongsTo('People', [
  41. 'foreignKey' => 'person_id'
  42. ]);
  43.  
  44.  
  45.  
  46. And the problem is that i need to acces Tests->TestsRegistration->People:
  47. What i try:
  48. $this->Tests=$this->Tests->find('all',['contain'=>['Registration']
  49. ])
  50. ->distinct('test_id')
  51. ->matching('Registrations')// ->matching('TestsRegistrations'):this does norks because its says TestsRegistrations does not associated with Tests
  52. ));
  53. Its possible to acces Tests->Registration but since people is associated to TestsRegistrations i stuck
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement