Exemplo n.º 1
0
 /**
  * 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)
 {
     $child = clone $this->_parent;
     $child->name = KInflector::singularize($config->name);
     $config->append(array('entityset' => 'anahita:domain.entityset.onetomany', 'cardinality' => 'many', 'child_key' => $this->_parent->name, 'parent_delete' => AnDomain::DELETE_CASCADE, 'child' => $child));
     parent::_initialize($config);
 }
Exemplo n.º 2
0
 /**
  * Get the proxied entity. Since there could many entities proxied. The getObject method will try to
  * load all the proxied entities of the same type in order to reduce the number of calls
  * to the storage later on.
  *
  * @return AnDomainEntityAbstract
  */
 public function getObject()
 {
     //security check
     if (!isset($this->_object)) {
         $condition = array($this->_property => $this->_value);
         $repository = AnDomain::getRepository($this->getIdentifier());
         //check if an entity exiting in the repository with $condition
         if ($data = $repository->find($condition, false)) {
             $this->_object = $data;
             return $this->_object;
         }
         //now time to fetch the object from the database
         //but lets grab all the similar entities all together
         $handle = $this->getIdentifier() . $this->_property;
         $values = isset(self::$_values[$handle]) ? self::$_values[$handle] : array();
         if (empty($values)) {
             return;
         }
         $values = AnHelperArray::unique($values);
         $query = $repository->getQuery();
         AnDomainQueryHelper::applyFilters($query, $this->_relationship->getQueryFilters());
         $query->where(array($this->_property => $values));
         $entities = $repository->fetchSet($query);
         //the object must have been fetched with the set
         //in the previous line
         //if the object is still not fetched, then the object
         //doesn't exists in the databse
         $this->_object = $repository->find($condition, false);
         if (!$this->_object) {
             //lets cache the null result to prevent re-fetching
             //the same result
             $query = $repository->getQuery()->where($condition)->limit(1);
             if ($repository->hasBehavior('cachable')) {
                 $repository->emptyCache($query);
             }
             $this->_object = false;
             //if it's a required one-to-one relationship
             //then instantaite a new entity if the entity doesn't exists
             if ($this->_relationship->isOneToOne()) {
                 if ($this->_relationship->isRequired()) {
                     $this->_object = $repository->getEntity(array('data' => array($this->_property => $this->_value)));
                 }
             }
         }
         unset(self::$_values[$handle]);
     }
     return $this->_object;
 }
Exemplo n.º 3
0
 /**
  * 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)
 {
     //disable the chain for the belongs to relationship
     $config->append(array('query' => array('disable_chain' => true)));
     parent::_initialize($config);
 }