Previously on the blog
RSS feed
  1. Using POG with Flex
  2. Optimizing your web application
  3. Regenerating large objects
  4. PHP4 or PHP5
  5. New and Improved
  6. Evolution of a cube
  7. POG Museum
  8. POG 3.0 alpha
  9. Initial Performance results Part 2
  10. Initial performance results
  11. Proposal: POG 3.0 object model
  12. Suggest a feature
  13. A new year, A new POG release
  14. Many-Many relations
  15. POG 2.5 Released
  16. POG 2.5 beta
  17. Automatic table alignment
  18. New version: 2.1.2 released
  19. RSS should work well now
  20. RSS feed glitches
  21. What's new in 2.1.0
  22. PHP Objects 2.1.0 (preview)
  23. PHP Object relations FAQ
  24. PHP Object Relations
  25. Searching base64 encoded text
  26. How to debug POG-generated objects
  27. POG UI Tips
  28. Featuring Of Interest links
  29. PHP CRUD
  30. POG 2.0.1: A better code generator
  31. A look at the POG SOAP API
  32. POG 2.0.0 released
  33. Coming soon: Generate parent-child objects
  34. Generated abstraction v/s dynamic abstraction
  35. Zend Framework preview
  36. Coming soon: Generate Objects through SOAP
  37. Easily save images and files to a database
  38. PHP, Paypal & POG
  39. Five advanced Code Generator tips
  40. PHP Pagination using generated objects
  41. PHP Code Generator benchmarks
  42. Representing database objects using an AJAX Tree interface
  43. Using SETUP in a production environment
  44. Description of the generated object package
  45. Introducing PHP Object Generator version 1.6
  46. Using AJAX and PHP Object Generator
  47. When to use Object->SaveNew()
  48. Generating PHP objects in 2006
  49. Happy Holidays
  50. A short video of the POG Setup process
  51. A sneak peek at POG 1.6
  52. POG Tip: Field limits
  53. Previous versions.
  54. Searching the blog and tutorials sections
  55. Generating code with "Other" SQL data types
  56. Five general POG tips
  57. POG source code locations
  58. Microsoft SQL 2005 Express Edition
  59. Impatiently awaiting PHP 5.1 and PDO
  60. Php Object Generator goes open source
  61. POG generates PDO compatible code
  62. Oracle to offer free database
  63. POG Google group
  64. Database Wrappers and POG
  65. Revisions
  66. The generator blog
  67. An explanation of the 'Escape' function.
  68. Mirror, mirror
  69. Using POG to solve real world problems
  70. A php object-relational database tool
  71. A simple and flexible Object Oriented approach to PHP


Want more Php Object Generator?
Back to the Code Generator
The POG Google group
The POG tutorials/code samples
The POG mirror site




PHP Object Relations

written 4203 days ago

After some discussion in the POG Google group, it seems that we haven’t done a good enough job yet, explaining how to use POG’s optional ability to generate object-relations code. So, here it goes:

In addition to the basic 5 CRUD methods (Get, Save, GetList, SaveNew and Delete), POG is able to generate additional methods for “connected objects”. These additional methods are only generated if, upon generation, you have chosen 1 or more attributes to be of type “Child” or “Parent” from the drop-down list in the POG interface.

More often than not, objects are related to each-other in an application, so it makes sense for developers to take advantage of these generated methods. However, a developer can still decide to implement object relations without going through POG’s child/parent concept. In this case, the developer would then generate objects containing attributes that can be used as foreign keys to match them with other objects.

Explanation of POG’s parent/child concept.
POG’s parent/child concept is quite simple and is essentially an implementation of 1-to-many and many-to-1relations. A parent object can have many children (1-to-many). Many children can refer to the same parent (many-to-1). Using POG to generate Many-to-many relations is a little less obvious and currently not supported out-of-the-box, but we’re working to correct this in the next release.

Programmatic meaning:
It might be worth mentioning what a Parent or Child attribute mean on a programmatic level in POG.

RULE A
When object “P” contains a Child attribute “C”, it means that P will have:
1. a method GetCList() will be generated. GetCList returns a list of all children for parent P.
2. a method AddC() will be generated. AddC() will add any child C to the list of children belonging to P.
3. the ability to save all children, grand-children, grand-grand children etc. recursively through Save($deep).
4. the ability to delete all children, grand-children, grand-grand children etc. recursively through Delete($deep).

RULE B
When an object “C” contains a Parent attribute “P”, it means that C will have:
1. an attribute pId which refers to the Id of the Parent object.
2. A GetP() method which fetches the parent object.
3. A SetP() method which sets the parent object.

How to use POG’s interface to generate object relations. (Examples)
The rule of thumb is: Whenever an object P has a attribute C of type {Child}, the child object C must also have an attribute P of type {Parent}.

Example #1.

Solution:
Create an “Author” object with the following attributes:

Create a “Book” object with the following attributes:

Create a “Publisher” object with the following attributes:

Example #2

Solution:
Create a “Project” object with the following attributes:

Create a “Task” object with the following attributes:

Create a “Developer” object with the following attributes:

Over the next little while, we’ll be adding some more info about Relations to the POG documentation as well as to the blog, and we hope some of you find it useful.


The Example #2 on PHP Object Relations has a little bug. A developer has a name, a title and one or more tasks ({Child}), and belongs to one project ({Parent}). Therefore, the “Developer” object must be assigned as the ({Child}) of the “Project” object rather than the “Task” object.

Best Regards,

Chris
Technical Director
ProFormPlus – Secure Online Forms


Chris Kunze    May 1, 10:14 AM    #

Thanks for noticing the error. Fixed.


Pog Guys    May 1, 10:21 AM    #

  Textile Help
About Php Object Generator
This is a weblog about the Php Object Generator (POG) project, OO PHP, databases and Php code generators in general.

Php Object Generator, (POG) is an open source PHP code generator which automatically generates clean & tested Object Oriented code for your PHP4/PHP5 application.

Subscribe to our RSS feed

Feedback, Feature Requests, Bugs to:
The POG Google group

Send us a Hello through email