本文整理汇总了PHP中Jam::find_or_create方法的典型用法代码示例。如果您正苦于以下问题:PHP Jam::find_or_create方法的具体用法?PHP Jam::find_or_create怎么用?PHP Jam::find_or_create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jam
的用法示例。
在下文中一共展示了Jam::find_or_create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_deep
public function test_deep()
{
$blog = Jam::find_or_create('test_blog', array('id' => 10, 'name' => 'created blog'));
$author = Jam::build('test_author')->load_fields(array('id' => 4, 'name' => 'Joe', 'test_posts' => array(array('id' => 1, 'name' => 'hardware', 'test_categories' => array(array('id' => 1, 'name' => 'cat1'), array('id' => 2, 'name' => 'cat2')), 'test_blog' => array('id' => 2, 'name' => 'loaded')), array('id' => 2, 'name' => 'software', 'test_categories' => array(array('id' => 1, 'name' => 'cat1'), array('id' => 3, 'name' => 'cat3')), 'test_blog' => 10))));
$post = Jam::build('test_post')->load_fields(array('id' => 3, 'name' => 'administration'));
$post2 = Jam::build('test_post', array('name' => 'unsaved'));
$author->test_posts->add($post)->add($post2);
$serialized_data = serialize($author);
$unserialized = unserialize($serialized_data);
$this->assertNotSame($author, $unserialized);
$this->assertTrue($unserialized->loaded());
$this->assertEquals($author->as_array(), $unserialized->as_array());
$this->assertCount(4, $unserialized->test_posts);
$this->assertTrue($unserialized->test_posts[0]->loaded());
$this->assertEquals($author->test_posts[0]->as_array(), $unserialized->test_posts[0]->as_array());
$this->assertNotNull($unserialized->test_posts[0]->test_blog);
$this->assertTrue($unserialized->test_posts[0]->test_blog->loaded());
$this->assertEquals($author->test_posts[0]->test_blog->as_array(), $unserialized->test_posts[0]->test_blog->as_array());
$this->assertNotNull($unserialized->test_posts[1]->test_blog);
$this->assertTrue($unserialized->test_posts[1]->test_blog->loaded());
$this->assertEquals($author->test_posts[1]->test_blog->as_array(), $unserialized->test_posts[1]->test_blog->as_array());
$this->assertEquals($blog->as_array(), $unserialized->test_posts[1]->test_blog->as_array());
$this->assertTrue($unserialized->test_posts[1]->loaded());
$this->assertEquals($author->test_posts[1]->as_array(), $unserialized->test_posts[1]->as_array());
$this->assertTrue($unserialized->test_posts[2]->loaded());
$this->assertEquals($author->test_posts[2]->as_array(), $unserialized->test_posts[2]->as_array());
$this->assertFalse($unserialized->test_posts[3]->loaded());
$this->assertEquals($author->test_posts[3]->as_array(), $unserialized->test_posts[3]->as_array());
$blog->delete();
}
示例2: set
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);
}
示例3: set
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);
}