Php Object Generator Tutorials
  1. Introduction to POG
  2. Setting up PHP, MySQL etc.
  3. Designing your objects
  4. Generating your code
  5. Description of the generated code
  6. Edit configuration file
  7. The Setup Process
  8. Using the code: Save()
  9. Using the code: Get()
  10. Using the code: SaveNew()
  11. Using the code: GetList()
  12. Using the code: Delete()
  13. Using the code: DeleteList()
  14. Advanced: object relations
  15. Advanced: Set{Parent}()
  16. Advanced: Get{Parent}()
  17. Advanced: Add{Child}()
  18. Advanced: Get{Child}List()
  19. Advanced: Save(deep)
  20. Advanced: Delete(deep)
  21. Advanced: Add{Sibling}()
  22. Advanced: Set{Child}List()
  23. Advanced: Set{Sibling}List()
  24. Advanced: Get{Sibling}List()
  25. Advanced: DeleteList(deep)
  26. Customizing POG-generated code
  27. Customizing: Extending POG Objects
  28. Customizing: Plugins
  29. Examples
  30. Examples: User registration system
  31. Examples: User authentication
  32. Examples: Survey form
  33. Examples: Using POG with AJAX
  34. PDO: Introduction
  35. PDO: SQLite example
  36. PDO: Firebird example
  37. PDO: PostgreSQL example
  38. PDO: MySQL example
  39. PDO: ODBC example
  40. Troubleshooting
  41. Troubleshooting: Data appears encoded
  42. Troubleshooting: Can't regenerate object
  43. Troubleshooting: Can't seem to Save()
  44. Troubleshooting: Can't get object / object attributes from database
  45. Troubleshooting: Can't open zip file on Mac
  46. Troubleshooting: Setup screen is blank
  47. Videos
  48. Appendix: Creating table(s) manually
  49. Appendix: Regenerating objects
  50. Appendix: Generating objects using SOAP
  51. Case Study: Gravity GTD
  52. Case Study: Web Form Factory

Want more Php Object Generator?
Back to the Code Generator
The POG Weblog and RSS feed.
The POG Google group

Advanced: object relations

In addition to the 6 essential CRUD methods, POG can also generate additional methods which facilitate object relations in PHP4 and PHP5.

Object relations are used to define how your objects relate to one another. Even in the simplest web application, when 1 or more objects are used, they are almost always connected in the logical sense. If you have an ‘Blog Article’ object and a ‘Comment’ object, these can be related by the definition: A blog article has many comments or even This comment belongs to this blog article

In the beginning, POG did not provide any out-of-the-box facilities for generating methods that would make object relations easy to program for. One had to manually add the reference attribute of 1 object within another object to establish the relations, much like when you define 2 database tables and connect them using a foreign key.

We then added object relations functionality to POG to accelerate application development and it was very well received.

POG can generate 3 types of connected objects:


Parent and Child objects are used if your objects have 1 to many or many to 1 relations. The blog and comment example used above is an excellent example of Parent and Child objects.

Sibling objects are used if your objects have many to many relations with each other.

When an object is identified as type ‘Parent’ or ‘Child’ or ‘Sibling’, POG generates the usual 6 CRUD methods as well as additional methods (referred to as relations methods) that accelerate application development even more. What follows is a description of the relations methods as well as code samples that demonstrate how they can be used.

Please note that these additional methods are only generated if a developer specifies that an object
is a Parent, Child or Sibling. Otherwise the object will be generated with only the usual 6 CRUD

To Specify that an object is a CHILD/PARENT/SIBLING of another, add the OBJECT NAME of target object as an attribute of the referring object and choose {CHILD} / {PARENT} /{SIBLING} from the drop down list. For example, to create an Author/Book parent-child relationship, do the following

Then do not forget to establish the relation in the target object as well:

Specifying relationship both ways is required for the objects to work properly. If the relations are not properly set up. you will get error messages when you run the POG Setup application.

Some blog posts about PHP Object Relations:

POG documentation summary: