Beispiel #1
0
 public function set(Jam_Validated $model, $value, $is_changed)
 {
     if ($is_changed and $value and is_string($value) and !is_numeric($value)) {
         $value = Jam::find_or_create($this->foreign_model, array(':name_key' => $value));
         if ($this->default_fields) {
             $value->set($this->default_fields);
         }
     }
     return parent::set($model, $value, $is_changed);
 }
Beispiel #2
0
 public function get(Jam_Validated $model, $value, $is_changed)
 {
     if (!$is_changed and !$value and !$model->loaded() and Jam_Association_Creator::current()) {
         $value = Jam::find($this->foreign_model, Jam_Association_Creator::current());
         $is_changed = TRUE;
         if ($this->inverse_of) {
             $value->{$this->inverse_of} = $model;
         }
     }
     return parent::get($model, $value, $is_changed);
 }
Beispiel #3
0
 public function set(Jam_Validated $model, $value, $is_changed)
 {
     if ($is_changed and $value and is_string($value) and !is_numeric($value)) {
         if ($this->default_fields and !$this->additional_fields) {
             $this->additional_fields = $this->default_fields;
         }
         if (!is_array($this->additional_fields)) {
             $this->additional_fields = array();
         }
         $value = Jam::find_or_create($this->foreign_model, array_merge(array(':name_key' => $value), $this->additional_fields));
     }
     return parent::set($model, $value, $is_changed);
 }
Beispiel #4
0
 public function test_load_fields()
 {
     $association = new Jam_Association_Belongsto(array());
     $association->initialize($this->meta, 'test_author');
     $model = new Model_Test_Post();
     $value = $association->load_fields($model, array('id' => 2, 'name' => 'Test'));
     $this->assertInstanceOf('Jam_Model', $value);
     $this->assertTrue($value->loaded());
     $this->assertEquals(2, $value->id());
     $this->assertEquals('Test', $value->name());
 }