예제 #1
0
 /**
  *
  * @return Yada_Field_Foreign
  */
 public function through()
 {
     var_dump('ManytoMany Through');
     if (!$this->through instanceof Yada_Field_Foreign) {
         $init = NULL;
         if (is_array($this->through)) {
             list($model, $field) = $this->through;
             if (is_array($model)) {
                 list($model, $init) = $model;
             }
         } elseif (is_string($this->through)) {
             $model = $this->through;
             $field = $this->related->name;
         } else {
             throw new Kohana_Exception('No through option specified for many-to-many field :field in model :model', array(':field' => $column, ':model' => Yada::common_name('model', $model)));
         }
         $model = Yada::model($model, $init);
         $dynamic = Yada::class_name('model', 'Dynamic');
         if ($model instanceof $dynamic) {
             $this->_init_dynamic($model, $field);
             $this->meta->attach($model);
         } else {
             // Focus the through model and get the meta data
             $meta = $this->meta->meta($model);
             // Get the Yada Field Object that points back to this model
             $field = $meta->fields->{$field};
             // Set that field's properties to point back to this model/field
             $field->related = $this;
             // Save the reference to that field
             $this->through = $field;
         }
     }
     // Focus the through model
     $this->meta->model($this->through);
     // return the through model
     return $this->through;
 }
예제 #2
0
파일: core.php 프로젝트: jerfowler/yada
 /**
  * Returns the current focused model, sets the focus if $class is specified
  *
  * @param Yada_Model|string $model
  * @return Yada_Model
  */
 public function model($model = NULL)
 {
     if ($model instanceof Yada_Model) {
         if (!$this->_models->contains($model)) {
             $this->attach($model);
         } else {
             $this->_current = $model;
             $this->_meta = $this->_models->offsetGet($this->_current);
         }
     } elseif (is_string($model)) {
         // Attach and initialize unknown models
         $model = Yada::model($model);
         $this->attach($model);
     }
     // Return the current Model object
     return $this->_current;
 }