awbush/coughphp — Issue #1: Generate (set|get|load|)_<entity>_Object() for PK
Author: awbush
Created: 2011-10-13 16:44:04+00:00
State: open

If there's a schema that has extended data in a different table that varies by a type ID, as in this example:

generic
-------
generic_id PK AUTO_INCREMENT
generic_type_id (indicates which extended table to join to, e.g. extension1, extension2, etc.)
[fields common amongst all extensions]

generic_extension1
------------------
generic_id PK, not AUTO_INCREMENT
[fields specific to the extension]

generic_extension2
------------------
generic_id PK, not AUTO_INCREMENT
[fields specific to the extension]

Then one might except there to be `getGeneric_Object()` method on the `GenericExtension*` classes. However, perhaps because this is the primary key, Cough does not look for these relationships.

Current workaround is to provide the methods manually on an as-needed basis:

public function loadGeneric_Object()
{
$this->setGeneric_Object(Generic::constructByKey($this->getKeyId()));
}

public function getGeneric_Object()
{
if (!isset($this->objects['Generic_Object']))
{
$this->loadGeneric_Object();
}
return $this->objects['Generic_Object'];
}

public function setGeneric_Object($generic)
{
$this->objects['Generic_Object'] = $generic;
}