Advertisement
Guest User

Untitled

a guest
Jan 10th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. Table: Employee
  2. | id | name | position |
  3. | 1 | Ned | kitchen |
  4. | 2 | Bob | server |
  5. | 3 | Jon | server |
  6.  
  7. Table: Tips
  8. | id | employee | date | amount
  9. | 1 | 1 | 2012-11-12 | 9.00
  10. | 2 | 2 | 2012-11-14 | 4.55
  11. | 3 | 1 | 2012-11-15 | 8.01
  12. | 4 | 2 | 2012-11-15 | 2.00
  13. | 5 | 1 | 2012-11-23 | 3.02
  14.  
  15. ------------------------------------
  16. Example code
  17. ------------------------------------
  18. $sdate = '2012-11-01';
  19. $edate = '2012-11-31';
  20. $entries = Model_Employee::find('all', array(
  21. 'related' => array(
  22. 'tips' => array(
  23. 'join_type' => 'left',
  24. 'where' => array(
  25. array('date', '>=', $sdate),
  26. array('date', '<=', $edate),
  27. ),
  28. ),
  29. )
  30. ));
  31.  
  32. ------------------------------------
  33.  
  34. Expected result:
  35.  
  36. Ned
  37. position => kitchen
  38. tips =>
  39. 9.00
  40. 8.01
  41. 3.02
  42. Bob
  43. position => server
  44. tips =>
  45. 4.55
  46. 2.00
  47. Jon
  48. position => server
  49. tips =>
  50.  
  51. ------------------------------------
  52.  
  53. Actual result:
  54.  
  55. Ned
  56. position => kitchen
  57. tips =>
  58. 9.00
  59. 8.01
  60. 3.02
  61. Bob
  62. position => server
  63. tips =>
  64. 4.55
  65. 2.00
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement