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); }
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); }
public function test_set_inverse_of() { $association = new Jam_Association_Belongsto(array('inverse_of' => 'test_post')); $association->initialize($this->meta, 'test_author'); $author = Jam::build('test_author'); $post = Jam::build('test_post')->load_fields(array('id' => 1, 'test_author_id' => 1)); $this->assertSame($post, $association->set($post, $author, TRUE)->test_post); }