Пример #1
0
 public function initialize(Yada_Meta $meta, Yada_Model $model, $name, $alias)
 {
     parent::initialize($meta, $model, $name, $alias);
     if (!isset($this->expression)) {
         throw new Exception('You must specifiy an Expression for ' . Yada::common_name('model', $model) . '->' . $name);
     }
 }
Пример #2
0
 public function related()
 {
     if (!$this->related instanceof Yada_Field_Interface_Related) {
         if (is_array($this->related) and count($this->related) == 2) {
             list($this->related, $field) = $this->related;
         } elseif (is_string($this->related)) {
             $field = $this->name;
         } else {
             throw new Kohana_Exception('Invalid related value for Field :field in Model :Model', array(':field' => $this->name, ':model' => Yada::common_name('model', $this->model)));
         }
         // Get the mapper and save it
         $this->mapper = $this->meta->mapper($this->model);
         // Focus the through model and get the meta data
         $meta = $this->meta->meta($this->related);
         // Get the Yada Field Object that points back to this model
         $field = $meta->fields->{$field};
         $field->mapper = $meta->mapper;
         // Set that field's related to point back to this field
         $field->related = $this;
         // Save the reference to that field
         $this->related = $field;
     }
     // Focus the related model
     $this->meta->model($this->related);
     return $this->related;
 }
Пример #3
0
 public function action_index()
 {
     $test = Yada::factory('Test');
     $test->begin()->name->like('%test%')->or_not_begin()->eq('Example 01')->and()->date->is_not(NULL)->end()->or()->condition->is(TRUE)->value->between(1, 2)->value->between(array(1, 2))->end();
     $test->load();
     //	    // These two are functionally the same
     //	    $test->field('name')->set('test');
     //	    $test->name = 'test';
     //
     //	    $test->values(array(
     //		'date' => time(),
     //		'value' => array(1,2)
     //	    ));
     //
     //	    // Automatic joins for related fields... Just have to reference it once...
     //	    $test->test3;
     //
     //
     //	    $test->field('test3')->select();
     //	    $test->field('test3')->join('INNER');
     //	    $test->test3->load();
 }
Пример #4
0
 public static function initialize(Yada_Model $model, Yada_Meta $meta)
 {
     $meta->initialize(array('fields' => array('id' => Yada::field('Primary'), 'test2' => Yada::field('Foreign', array('related' => array('Test2', 'test'))), 'name' => Yada::field('Name'), 'description' => Yada::field('String'), 'value' => Yada::field('Integer'), 'condition' => Yada::field('Boolean'), 'number' => Yada::field('Float'), 'stamp' => Yada::field('Timestamp'), 'date' => Yada::field('DateTime'), 'test3' => Yada::field('ManyToMany', array('related' => array('Test3', 'test')))), 'table' => 'tests'));
 }
Пример #5
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;
 }
Пример #6
0
 public function related($action, $value)
 {
     var_dump('Related, model: ' . Yada::common_name('model', $this->_model));
     var_dump('Related, action: ' . $action);
     $related = $this->_related();
     $name = $this->_field->name;
     var_dump('Related, name: ' . $name);
     if (!$related->offsetExists($action)) {
         $related[$action] = array($name => $value);
     } else {
         $related[$action][$name] = $value;
     }
     $this->_state = 'changed';
     return $this;
 }
Пример #7
0
 /**
  * Sets the model's field values
  *
  * @param Yada_Model $model
  * @param string $name field name
  * @param mixed $value
  * @return mixed
  */
 public function set_field(Yada_Model $model, $name, $value)
 {
     // Focus the model and get the Field's meta data
     $fields = $this->fields($model);
     // Throw error if field doesn't exist
     if (!$fields->offsetExists($name)) {
         throw new Kohana_Exception('Field :name doesn\'t exist in Model :model', array(':name' => $name, ':model' => Yada::common_name('model', $model)));
     }
     // Get the Yada_Field Object
     $field = $fields[$name];
     $this->mapper()->field($model, $field)->set($value);
     return $value;
 }