/** * Creates a belongs to relationship (many to one). * * @param KConfig $config Relationship options * * @return AnDomainRelationshipManytoone */ protected static function _belongsTo(KConfig $config) { $description = $config['description']; $config['child'] = $description->getEntityIdentifier(); $config->append(array('type_column' => KInflector::underscore($config->name) . '_type', 'child_column' => KInflector::underscore($config->name) . '_id')); if (is_string($config->type_column)) { $config->type_column = $description->getRepository()->getResources()->getColumn($config->type_column); } if (is_string($config->child_column)) { $config->child_column = $description->getRepository()->getResources()->getColumn($config->child_column); } if (!$config->child_column) { throw new AnDomainPropertyException('The ' . $config->name . ' belongs to relationship is missing a child column'); } //if the relationship is not polymorphic the we need to set //a parent if none is set if (!$config->polymorphic && !$config['parent']) { $parent = clone $description->getEntityIdentifier(); $parent->name = $config['name']; $config->append(array('parent' => $parent)); } if (is_string($config->parent) && strpos($config->parent, '.') === false) { $parent = clone $description->getEntityIdentifier(); $parent->name = $config->parent; $config->parent = $parent; } $relationship = AnDomainPropertyAbstract::getInstance('relationship.manytoone', $config); if ($config->inverse) { if (is_bool($config->inverse)) { $config['inverse'] = array(); } $relationship->setInverse($config->inverse); } return $relationship; }
/** * Set a property description * * @param AnDomainPropertyAbstract $property The property to set * * @return AnDomainDescriptionAbstract */ public function setProperty($property) { $this->_properties[$property->getName()] = $property; //if property name is the same as the identity property //then set the identity property if (is_string($this->_identity_property) && $property->getName() == $this->_identity_property) { $this->setIdentityProperty($property); } return $this; }
/** * Initializes the options for the object * * Called from {@link __construct()} as a first step of object instantiation. * * @param object An optional KConfig object with configuration options. * @return void */ protected function _initialize(KConfig $config) { $config->append(array('parent_key' => 'id', 'query' => array())); parent::_initialize($config); }
/** * Initializes the options for the object. * * Called from {@link __construct()} as a first step of object instantiation. * * @param object An optional KConfig object with configuration options. */ protected function _initialize(KConfig $config) { $config->append(array('type' => 'string')); parent::_initialize($config); }