Guest User

Untitled

a guest
May 27th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. <?php
  2.  
  3. // ...
  4. class Project extends Project_Generated implements CoughObjectStaticInterface {
  5. // ...
  6.  
  7. /**
  8. * Override the default load method for category2project to pull category and
  9. * category type data in same query.
  10. *
  11. * @return void
  12. * @author Anthony Bush
  13. **/
  14. public function loadCategory2Project_Collection()
  15. {
  16. // Always create the collection
  17. $collection = new Category2project_Collection();
  18. $this->setCategory2project_Collection($collection);
  19.  
  20. // But only populate it if we have key ID
  21. if (!$this->hasKeyId()) {
  22. return;
  23. }
  24.  
  25. $db = Category2project::getDb();
  26. $tableName = Category2project::getTableName();
  27. $sql = '
  28. SELECT
  29. `' . $tableName . '`.*
  30. , ' . implode("\n\t, ", CoughObject::getFieldAliases('Category', 'Category_Object')) . '
  31. , ' . implode("\n\t, ", CoughObject::getFieldAliases('CategoryType', 'CategoryType_Object')) . '
  32. FROM
  33. `' . Category2project::getDbName() . '`.`' . $tableName . '`
  34. INNER JOIN `' . Category::getDbName() . '`.`' . Category::getTableName() . '` ON
  35. `' . Category::getTableName() . '`.category_id = `' . $tableName . '`.category_id
  36. INNER JOIN `' . CategoryType::getDbName() . '`.`' . CategoryType::getTableName() . '` ON
  37. `' . CategoryType::getTableName() . '`.category_type_id = `' . Category::getTableName() . '`.category_type_id
  38. WHERE
  39. `' . $tableName . '`.`project_id` = ' . $db->quote($this->getProjectId()) . '
  40. ';
  41.  
  42. // Construct and populate the collection
  43. $collection->loadBySql($sql);
  44. foreach ($collection as $element) {
  45. $element->setProject_Object($this);
  46. }
  47.  
  48. }
  49.  
  50. // ...
  51. }
Add Comment
Please, Sign In to add comment