本文整理汇总了PHP中Picture::isNewRecord方法的典型用法代码示例。如果您正苦于以下问题:PHP Picture::isNewRecord方法的具体用法?PHP Picture::isNewRecord怎么用?PHP Picture::isNewRecord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Picture
的用法示例。
在下文中一共展示了Picture::isNewRecord方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_for_has_many
public function test_for_has_many()
{
$Property = new Property();
$this->assertEqual($Property->picture->getType(), 'hasMany');
$this->assertTrue(is_array($Property->pictures) && count($Property->pictures) === 0);
$Property->picture->load();
$this->assertEqual($Property->picture->count(), 0);
$SeaViews = new Picture(array('title' => 'Sea views'));
$Property->picture->add($SeaViews);
$this->assertEqual($Property->picture->count(), 1);
$this->assertReference($Property->pictures[0], $SeaViews);
$Property->picture->add($SeaViews);
$this->assertEqual($Property->picture->count(), 1);
$this->assertNull($Property->pictures[0]->get('property_id'));
$MountainViews = new Picture(array('title' => 'Mountain views'));
$this->assertTrue($MountainViews->isNewRecord());
$Property->picture->add($MountainViews);
$this->assertEqual($Property->picture->count(), 2);
$this->assertTrue($Property->save());
$this->assertFalse($SeaViews->isNewRecord());
$this->assertFalse($MountainViews->isNewRecord());
$this->assertEqual($SeaViews->get('property_id'), $Property->getId());
$this->assertEqual($MountainViews->get('property_id'), $Property->getId());
$this->assertReference($SeaViews, $Property->pictures[0]);
$this->assertReference($MountainViews, $Property->pictures[1]);
$Property = new Property($Property->getId());
$Property->picture->load();
$this->assertEqual($Property->picture->association_id, 'pictures');
$this->assertEqual($Property->picture->count(), 2);
$Property->pictures = array();
$this->assertEqual($Property->picture->count(), 0);
$Property->picture->load();
$this->assertEqual($Property->picture->count(), 0);
$Property->picture->load(true);
$this->assertEqual($Property->picture->count(), 2);
$this->assertEqual($Property->pictures[1]->getType(), 'Picture');
$Property->picture->delete($Property->pictures[1]);
$this->assertEqual($Property->picture->count(), 1);
$Property->picture->load(true);
$this->assertEqual($Property->picture->count(), 1);
$Property = $Property->find('first');
$Picture = new Picture();
$Pictures = $Picture->find();
$Property->picture->set($Pictures);
$this->assertEqual($Property->picture->count(), count($Pictures));
$Property = $Property->find('first');
$Property->picture->load();
$this->assertEqual($Property->picture->count(), count($Pictures));
$Picture = $Picture->find('first');
$Property->picture->set($Picture);
$this->assertEqual($Property->picture->count(), 1);
$this->assertTrue(in_array('pictures', $Property->getAssociatedIds()));
$Property = $Property->find('first', array('include' => 'pictures'));
$this->assertIdentical($Property->picture->count(), 1);
$this->assertEqual($Property->pictures[0]->getId(), $Picture->getId());
$this->assertTrue($Property->picture->delete($Property->pictures[0]));
$this->assertIdentical($Property->picture->count(), 0);
$Property =& $Property->find('first');
$this->assertIdentical($Property->picture->count(), 0);
//$this->assertTrue($Property =& $Property->find('first', array('include'=>'pictures')));
//$this->assertIdentical($Property->picture->count(), 0);
$Picture = new Picture();
$Alicia =& $Picture->create(array('title' => 'Alicia'));
$Bermi =& $Picture->create(array('title' => 'Bermi'));
$Hilario =& $Picture->create(array('title' => 'Hilario'));
$Property->picture->setByIds(array($Alicia->getId(), $Bermi->getId(), $Hilario->getId()));
$Property->set('description', 'Cool house');
$this->assertTrue($Property->save());
$this->assertTrue($Property =& $Property->findFirstBy('description', 'Cool house'));
$Property->picture->load();
$this->assertEqual($Property->picture->count(), 3);
$FoundAlicia = $Property->picture->find('first', array('conditions' => array('title = ?', "Alicia")));
$this->assertEqual($Alicia->get('title') . $Alicia->getId(), $FoundAlicia->get('title') . $FoundAlicia->getId());
$FoundPals = $Property->picture->find();
$this->assertEqual(count($FoundPals), $Property->picture->count());
$titles = array();
foreach ($FoundPals as $FoundPal) {
$titles[] = $FoundPal->get('title');
}
sort($titles);
$this->assertEqual($titles, array('Alicia', 'Bermi', 'Hilario'));
$this->assertFalse($Property->picture->isEmpty());
$this->assertEqual($Property->picture->getSize(), 3);
$this->assertTrue($Property->picture->clear());
$this->assertTrue($Property->picture->isEmpty());
$this->assertEqual($Property->picture->getSize(), 0);
$Property = new Property();
$PoolPicture =& $Property->picture->build(array('title' => 'Pool'));
$this->assertReference($PoolPicture, $Property->pictures[0]);
$this->assertTrue($Property->pictures[0]->isNewRecord());
$this->assertEqual($PoolPicture->getType(), 'Picture');
$Property->set('description', 'Maui Estate');
$this->assertTrue($Property->save());
$this->assertTrue($MauiEstate = $Property->findFirstBy('description', 'Maui Estate', array('include' => 'pictures')));
$this->assertEqual($MauiEstate->pictures[0]->get('title'), 'Pool');
$Property = new Property(array('description' => 'Villa Altea'));
$GardenPicture =& $Property->picture->create(array('title' => 'Garden'));
$this->assertReference($GardenPicture, $Property->pictures[0]);
$this->assertTrue($GardenPicture->isNewRecord());
$Property = new Property(array('description' => 'Villa Altea'));
//.........这里部分代码省略.........
示例2: test_for_single_has_one_association
public function test_for_single_has_one_association()
{
$Picture = new Picture(array('title' => 'The Akelos Media Team at SIMO'));
$this->assertReference($Picture, $Picture->hasOne->Owner);
$this->assertEqual($Picture->main_thumbnail->getAssociationId(), 'main_thumbnail');
$this->assertEqual($Picture->main_thumbnail->getType(), 'hasOne');
$this->assertFalse($Picture->main_thumbnail->getId());
$Thumbnail = new Thumbnail(array('caption' => 'SIMO 2005'));
$Picture->main_thumbnail->assign($Thumbnail);
$this->assertEqual($Picture->main_thumbnail->getAssociationId(), 'main_thumbnail');
$this->assertEqual($Picture->main_thumbnail->getType(), 'Thumbnail');
$this->assertEqual($Picture->main_thumbnail->getAssociationType(), 'hasOne');
$this->assertFalse($Picture->main_thumbnail->getId());
$this->assertTrue($Picture->save());
$this->assertFalse($Picture->isNewRecord());
$this->assertFalse($Thumbnail->isNewRecord());
$this->assertReference($Thumbnail, $Picture->main_thumbnail);
$SimoPic = $Picture->findFirstBy('title:has', 'SIMO');
$this->assertTrue(empty($SimoPic->main_thumbnail->caption));
$this->assertEqual($SimoPic->main_thumbnail->getAssociatedType(), 'hasOne');
$this->assertEqual($Picture->main_thumbnail->getAssociatedType(), 'hasOne');
$SimoPic = $Picture->findFirstBy('title:has', 'SIMO', array('include' => 'main_thumbnail'));
$this->assertEqual($SimoPic->title, 'The Akelos Media Team at SIMO');
$this->assertEqual($SimoPic->main_thumbnail->caption, 'SIMO 2005');
$Picture = new Picture(array('title' => 'The Akelos Media Team at CeBIT'));
$Picture->main_thumbnail->build(array('caption' => 'CeBIT 2005'));
$this->assertTrue($Picture->save());
$this->assertFalse($Picture->isNewRecord());
$this->assertFalse($Picture->main_thumbnail->isNewRecord());
$CeBitPic = $Picture->findFirstBy('title:has', 'CeBIT', array('include' => 'main_thumbnail'));
$this->assertEqual($CeBitPic->title, 'The Akelos Media Team at CeBIT');
$this->assertEqual($CeBitPic->main_thumbnail->caption, 'CeBIT 2005');
$Picture = new Picture(array('title' => 'The Akelos Media Team at Carlet'));
$this->assertTrue($Picture->save());
$this->assertFalse($Picture->findFirstBy('title:has', 'Carlet', array('include' => 'main_thumbnail')));
$this->assertTrue($CarletPic = $Picture->findFirstBy('title:has', 'Carlet', array('include' => array('main_thumbnail' => array('conditions' => false)))));
$this->assertEqual($CarletPic->title, 'The Akelos Media Team at Carlet');
///////////
$this->assertReference($CarletPic->main_thumbnail->_AssociationHandler->Owner, $CarletPic);
$CarletPic = $Picture->findFirstBy('title:has', 'Carlet');
///////////
$this->assertReference($CarletPic->main_thumbnail->_AssociationHandler->Owner, $CarletPic);
$this->assertEqual($CarletPic->title, 'The Akelos Media Team at Carlet');
$this->assertEqual($CarletPic->main_thumbnail->getType(), 'hasOne');
$CarletPic->main_thumbnail->create(array('caption' => 'Carlet'));
///////////
$this->assertReference($CarletPic->main_thumbnail->_AssociationHandler->Owner, $CarletPic);
$this->assertFalse($CarletPic->main_thumbnail->isNewRecord());
$CarletPic = $Picture->findFirstBy('title:has', 'Carlet', array('include' => 'main_thumbnail'));
$this->assertEqual($CarletPic->main_thumbnail->caption, 'Carlet');
///////////
$this->assertReference($CarletPic->main_thumbnail->_AssociationHandler->Owner, $CarletPic);
$this->assertTrue($SimoPic->destroy());
$this->assertFalse($Picture->findFirstBy('title:has', 'SIMO', array('include' => 'main_thumbnail')));
$this->assertFalse($Thumbnail->findFirstBy('caption', 'SIMO 2005'));
$Thumbnail = new Thumbnail(array('caption' => 'Our Office'));
///////////
$this->assertReference($CarletPic->main_thumbnail->_AssociationHandler->Owner, $CarletPic);
$this->assertReference($CarletPic->main_thumbnail->replace($Thumbnail), $Thumbnail);
$this->assertReference($CarletPic->main_thumbnail, $Thumbnail);
//$this->assertReference($CarletPic->prueba, $Thumbnail);
$this->assertTrue($CarletPic->save());
$this->assertEqual($CarletPic->main_thumbnail->caption, 'Our Office');
$this->assertFalse($Thumbnail->findFirstBy('caption', 'Carlet'));
$this->assertTrue($OfficeThumbnail = $Thumbnail->findFirstBy('caption', 'Our Office'));
$this->assertEqual($OfficeThumbnail->getId(), $CarletPic->main_thumbnail->getId());
$NewThumbnail = new Thumbnail(array('caption' => 'Lucky (our pet)'));
$CarletPic->main_thumbnail->replace($NewThumbnail);
$this->assertTrue($CarletPic->save());
$CarletPic = $Picture->findFirstBy('title:has', 'Carlet', array('include' => 'main_thumbnail'));
$this->assertEqual($CarletPic->main_thumbnail->caption, 'Lucky (our pet)');
$CarletPic = $Picture->findFirstBy('title:has', 'Carlet');
$CarletPic->main_thumbnail->load();
$this->assertEqual($CarletPic->main_thumbnail->caption, 'Lucky (our pet)');
$this->assertFalse($NewThumbnail->findFirstBy('caption', 'Our Office'));
}